revert test change will be moved to an other branch

bzr revid: al@openerp.com-20121216193932-foluon7b5bqqvrib
This commit is contained in:
Antony Lesuisse
2012-12-16 20:39:32 +01:00
parent 70aa2c995a
commit 9568552636
3 changed files with 105 additions and 18 deletions
+8
View File
@@ -5,3 +5,11 @@ import test_ir_values
import test_menu
import test_search
checks = [
test_base,
test_expression,
test_ir_attachment,
test_ir_values,
test_menu,
test_search,
]
+79 -18
View File
@@ -456,9 +456,15 @@ def get_modules_with_version():
continue
return res
def get_test_modules(module):
""" Return a list of module for the addons potentialy containing tests to
feed unittest2.TestLoader.loadTestsFromModule() """
def get_test_modules(module, submodule, explode):
"""
Return a list of submodules containing tests.
`submodule` can be:
- None
- the name of a submodule
- '__fast_suite__'
- '__sanity_checks__'
"""
# Turn command-line module, submodule into importable names.
if module is None:
pass
@@ -466,21 +472,74 @@ def get_test_modules(module):
module = 'openerp.tests'
else:
module = 'openerp.addons.' + module + '.tests'
# Try to import the module
try:
__import__(module)
except Exception, e:
# If module has no `tests` sub-module, no problem.
if str(e) != 'No module named tests':
_logger.exception('Can not `import %s`.', module)
return []
if explode:
print 'Can not `import %s`.' % module
import logging
logging.exception('')
sys.exit(1)
else:
if str(e) == 'No module named tests':
# It seems the module has no `tests` sub-module, no problem.
pass
else:
_logger.exception('Can not `import %s`.', module)
return []
# include submodules too
result = []
for name in sys.modules:
if name.startswith(module):
result.append(sys.modules[name])
return result
# Discover available test sub-modules.
m = sys.modules[module]
submodule_names = sorted([x for x in dir(m) \
if x.startswith('test_') and \
isinstance(getattr(m, x), types.ModuleType)])
submodules = [getattr(m, x) for x in submodule_names]
def show_submodules_and_exit():
if submodule_names:
print 'Available submodules are:'
for x in submodule_names:
print ' ', x
sys.exit(1)
if submodule is None:
# Use auto-discovered sub-modules.
ms = submodules
elif submodule == '__fast_suite__':
# Obtain the explicit test sub-modules list.
ms = getattr(sys.modules[module], 'fast_suite', None)
# `suite` was used before the 6.1 release instead of `fast_suite`.
ms = ms if ms else getattr(sys.modules[module], 'suite', None)
if ms is None:
if explode:
print 'The module `%s` has no defined test suite.' % (module,)
show_submodules_and_exit()
else:
ms = []
elif submodule == '__sanity_checks__':
ms = getattr(sys.modules[module], 'checks', None)
if ms is None:
if explode:
print 'The module `%s` has no defined sanity checks.' % (module,)
show_submodules_and_exit()
else:
ms = []
else:
# Pick the command-line-specified test sub-module.
m = getattr(sys.modules[module], submodule, None)
ms = [m]
if m is None:
if explode:
print 'The module `%s` has no submodule named `%s`.' % \
(module, submodule)
show_submodules_and_exit()
else:
ms = []
return ms
def run_unit_tests(module_name):
"""
@@ -488,9 +547,14 @@ def run_unit_tests(module_name):
Return None if no test was found.
"""
import unittest2
ms = get_test_modules(module_name)
ms = get_test_modules(module_name, '__fast_suite__', explode=False)
# TODO: No need to try again if the above call failed because of e.g. a syntax error.
ms.extend(get_test_modules(module_name, '__sanity_checks__', explode=False))
suite = unittest2.TestSuite()
for m in ms:
suite.addTests(unittest2.TestLoader().loadTestsFromModule(m))
if ms:
_logger.log(logging.TEST, 'module %s: running test.', module_name)
_logger.log(logging.TEST, 'module %s: executing %s `fast_suite` and/or `checks` sub-modules', module_name, len(ms))
# Use a custom stream object to log the test executions.
class MyStream(object):
def __init__(self):
@@ -506,9 +570,6 @@ def run_unit_tests(module_name):
c = '` ' + c
first = False
_logger.log(logging.TEST, c)
suite = unittest2.TestSuite()
for m in ms:
suite.addTests(unittest2.TestLoader().loadTestsFromModule(m))
result = unittest2.TextTestRunner(verbosity=2, stream=MyStream()).run(suite)
if result.wasSuccessful():
return True
+18
View File
@@ -22,4 +22,22 @@ import test_translate
import test_uninstall
import test_view_validation
fast_suite = [
test_ir_sequence,
test_ir_filters
]
checks = [
test_expression,
test_mail,
test_db_cursor,
test_orm,
test_fields,
test_basecase,
test_view_validation,
test_misc,
test_osv,
test_translate,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: