PyXR

c:\python24\lib\site-packages\win32 \ com \ test \ testPippo.py



0001 import sys
0002 import unittest
0003 import pythoncom
0004 from win32com.client import Dispatch
0005 from win32com.client.gencache import EnsureDispatch
0006 
0007 class PippoTester(unittest.TestCase):
0008     def setUp(self):
0009         try:
0010             self.object = Dispatch("Python.Test.Pippo")
0011         except pythoncom.com_error:
0012             # register the server
0013             import pippo_server
0014             pippo_server.main([pippo_server.__file__])
0015             self.object = Dispatch("Python.Test.Pippo")
0016 
0017     def testLeaks(self):
0018         try:
0019             gtrc = sys.gettotalrefcount
0020         except AttributeError:
0021             print "Please run this with python_d for leak tests"
0022             gtrc = lambda: 0
0023         # note creating self.object() should have consumed our "one time" leaks
0024         self.object.Method1()
0025         start = gtrc()
0026         for i in range(1000):
0027             object = Dispatch("Python.Test.Pippo")
0028             object.Method1()
0029         object = None
0030         end = gtrc()
0031         if end-start > 5:
0032             self.fail("We lost %d references!" % (end-start,))
0033 
0034     def testLeaksGencache(self):
0035         try:
0036             gtrc = sys.gettotalrefcount
0037         except AttributeError:
0038             print "Please run this with python_d for leak tests"
0039             gtrc = lambda: 0
0040         # note creating self.object() should have consumed our "one time" leaks
0041         object = EnsureDispatch("Python.Test.Pippo")
0042         start = gtrc()
0043         for i in range(1000):
0044             object = EnsureDispatch("Python.Test.Pippo")
0045             object.Method1()
0046         object = None
0047         end = gtrc()
0048         if end-start > 10:
0049             self.fail("We lost %d references!" % (end-start,))
0050 
0051 if __name__=='__main__':
0052     unittest.main()
0053 

Generated by PyXR 0.9.4
SourceForge.net Logo