Merge extensions/python/xpcom changes from DOM_AGNOSTIC2_BRANCH into the

trunk.


git-svn-id: svn://10.0.0.236/trunk@187878 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mhammond%skippinet.com.au
2006-01-20 05:50:28 +00:00
parent 28dfbf4814
commit d394dc834d
56 changed files with 1710 additions and 958 deletions

View File

@@ -1,4 +1,6 @@
# test tools for the pyxpcom
# test tools for the pyxpcom bindings
from xpcom import _xpcom
import unittest
# export a "getmemusage()" function that returns a useful "bytes used" count
# for the current process. Growth in this when doing the same thing over and
@@ -70,3 +72,55 @@ if have_pdh:
else:
def getmemusage():
return 0
# Test runner utilities, including some support for builtin leak tests.
class TestLoader(unittest.TestLoader):
def loadTestsFromTestCase(self, testCaseClass):
"""Return a suite of all tests cases contained in testCaseClass"""
leak_tests = []
for name in self.getTestCaseNames(testCaseClass):
real_test = testCaseClass(name)
leak_test = self._getTestWrapper(real_test)
leak_tests.append(leak_test)
return self.suiteClass(leak_tests)
def _getTestWrapper(self, test):
# later! see pywin32's win32/test/util.py
return test
def loadTestsFromModule(self, mod):
if hasattr(mod, "suite"):
ret = mod.suite()
else:
ret = unittest.TestLoader.loadTestsFromModule(self, mod)
assert ret.countTestCases() > 0, "No tests in %r" % (mod,)
return ret
def loadTestsFromName(self, name, module=None):
test = unittest.TestLoader.loadTestsFromName(self, name, module)
if isinstance(test, unittest.TestSuite):
pass # hmmm? print "Don't wrap suites yet!", test._tests
elif isinstance(test, unittest.TestCase):
test = self._getTestWrapper(test)
else:
print "XXX - what is", test
return test
# A base class our tests should derive from (well, one day it will be)
TestCase = unittest.TestCase
def suite_from_functions(*funcs):
suite = unittest.TestSuite()
for func in funcs:
suite.addTest(unittest.FunctionTestCase(func))
return suite
def testmain(*args, **kw):
new_kw = kw.copy()
if not new_kw.has_key('testLoader'):
new_kw['testLoader'] = TestLoader()
try:
unittest.main(*args, **new_kw)
finally:
_xpcom.NS_ShutdownXPCOM()
ni = _xpcom._GetInterfaceCount()
ng = _xpcom._GetGatewayCount()
if ni or ng:
print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)