[PATCH] sle

bzr revid: chm@openerp.com-20140318122250-22bt2bcfzvxowkvf
This commit is contained in:
chm@openerp.com
2014-03-18 13:22:50 +01:00
parent 9d026e3fe3
commit bbca8bd17e
2 changed files with 31 additions and 25 deletions
+24 -24
View File
@@ -356,30 +356,6 @@ class TestStream(object):
current_test = None
def run_unit_tests(module_name, dbname):
"""
:returns: ``True`` if all of ``module_name``'s tests succeeded, ``False``
if any of them failed.
:rtype: bool
"""
global current_test
current_test = module_name
mods = get_test_modules(module_name)
r = True
for m in mods:
tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m))
suite = unittest2.TestSuite(itertools.ifilter(runs_at_install, tests))
_logger.info('running %s tests.', m.__name__)
result = unittest2.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite)
if not result.wasSuccessful():
r = False
_logger.error("Module %s: %d failures, %d errors",
module_name, len(result.failures), len(result.errors))
current_test = None
return r
def runs_at(test, hook, default):
# by default, tests do not run post install
test_runs = getattr(test, hook, default)
@@ -396,6 +372,30 @@ def runs_at(test, hook, default):
runs_at_install = functools.partial(runs_at, hook='at_install', default=True)
runs_post_install = functools.partial(runs_at, hook='post_install', default=False)
def run_unit_tests(module_name, dbname, position=runs_at_install):
"""
:returns: ``True`` if all of ``module_name``'s tests succeeded, ``False``
if any of them failed.
:rtype: bool
"""
global current_test
current_test = module_name
mods = get_test_modules(module_name)
r = True
for m in mods:
tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m))
suite = unittest2.TestSuite(itertools.ifilter(position, tests))
_logger.info('running %s tests.', m.__name__)
result = unittest2.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite)
if not result.wasSuccessful():
r = False
_logger.error("Module %s: %d failures, %d errors",
module_name, len(result.failures), len(result.errors))
current_test = None
return r
def unwrap_suite(test):
"""
Attempts to unpack testsuites (holding suites or cases) in order to