Index: scripts/slave/unittests/expect_tests/unittest_helper.py |
diff --git a/scripts/slave/unittests/expect_tests/unittest_helper.py b/scripts/slave/unittests/expect_tests/unittest_helper.py |
index ed46917f7e4c08cfef16a651e81a1e71c8c6588f..c04dc0131e886dc7338cf8657cad4706b209e20e 100644 |
--- a/scripts/slave/unittests/expect_tests/unittest_helper.py |
+++ b/scripts/slave/unittests/expect_tests/unittest_helper.py |
@@ -6,6 +6,8 @@ import unittest |
from .type_definitions import Test, Result, MultiTest, FuncCall, Bind |
+from .util import covers |
+ |
def _SetUpClass(test_class): |
inst = test_class('__init__') |
@@ -29,7 +31,7 @@ def _RunTestCaseSingle(test_case, test_name, test_instance=None): |
test_instance.tearDown() |
-def UnittestTestCase(test_case, name_prefix='', ext='json'): |
+def UnittestTestCase(test_case): |
"""Yield a MultiTest or multiple Test instances for the unittest.TestCase |
derived |test_case|. |
@@ -47,48 +49,59 @@ def UnittestTestCase(test_case, name_prefix='', ext='json'): |
@type test_case: unittest.TestCase |
""" |
- name_prefix = name_prefix + test_case.__name__ |
- def _tests_from_class(cls, *args, **kwargs): |
- for test_name in unittest.defaultTestLoader.getTestCaseNames(cls): |
- yield Test( |
- name_prefix + '.' + test_name, |
- FuncCall(_RunTestCaseSingle, cls, test_name, *args, **kwargs), |
- ext=ext, break_funcs=[getattr(cls, test_name)], |
+ @covers(lambda: Test.covers_obj(test_case)) |
+ def _inner(): |
+ name_prefix = '.'.join((test_case.__module__, test_case.__name__)) |
+ |
+ def _tests_from_class(cls, *args, **kwargs): |
+ for test_name in unittest.defaultTestLoader.getTestCaseNames(cls): |
+ yield Test( |
+ name_prefix + '.' + test_name, |
+ FuncCall(_RunTestCaseSingle, cls, test_name, *args, **kwargs), |
+ expect_dir=Test.expect_dir_obj(cls), |
+ expect_base=cls.__name__ + '.' + test_name, |
+ break_funcs=[getattr(cls, test_name)], |
+ covers=Test.covers_obj(cls) |
+ ) |
+ |
+ if hasattr(test_case, '__expect_tests_serial__'): |
+ serial = getattr(test_case, '__expect_tests_serial__', False) |
+ else: |
+ default_setup = unittest.TestCase.setUpClass.im_func |
+ default_teardown = unittest.TestCase.tearDownClass.im_func |
+ serial = ( |
+ test_case.setUpClass.im_func is not default_setup or |
+ test_case.tearDownClass.im_func is not default_teardown) |
+ |
+ atomic = getattr(test_case, '__expect_tests_atomic__', False) |
+ if atomic or serial: |
+ yield MultiTest( |
+ name_prefix, |
+ FuncCall(_SetUpClass, test_case), |
+ FuncCall(_TearDownClass, Bind(name='context')), |
+ list(_tests_from_class(test_case, |
+ test_instance=Bind(name='context'))), |
+ atomic |
) |
+ else: |
+ for test in _tests_from_class(test_case): |
+ yield test |
+ return _inner |
+ |
+ |
+def _is_unittest(obj): |
+ return isinstance(obj, type) and issubclass(obj, unittest.TestCase) |
+ |
- if hasattr(test_case, '__expect_tests_serial__'): |
- serial = getattr(test_case, '__expect_tests_serial__', False) |
- else: |
- default_setup = unittest.TestCase.setUpClass.im_func |
- default_teardown = unittest.TestCase.tearDownClass.im_func |
- serial = ( |
- test_case.setUpClass.im_func is not default_setup or |
- test_case.tearDownClass.im_func is not default_teardown) |
- |
- atomic = getattr(test_case, '__expect_tests_atomic__', False) |
- if atomic or serial: |
- yield MultiTest( |
- name_prefix, |
- FuncCall(_SetUpClass, test_case), |
- FuncCall(_TearDownClass, Bind(name='context')), |
- list(_tests_from_class(test_case, test_instance=Bind(name='context'))), |
- atomic |
- ) |
- else: |
- for test in _tests_from_class(test_case): |
- yield test |
- |
- |
-def UnitTestModule(test_module, name_prefix='', ext='json'): |
+def UnitTestModule(test_module): |
"""Yield MultiTest's and/or Test's for the python module |test_module| which |
contains zero or more unittest.TestCase implementations. |
@type test_module: types.ModuleType |
""" |
- name_prefix = name_prefix + test_module.__name__ + '.' |
for name in dir(test_module): |
obj = getattr(test_module, name) |
- if isinstance(obj, type) and issubclass(obj, unittest.TestCase): |
- for test in UnittestTestCase(obj, name_prefix, ext): |
+ if _is_unittest(obj): |
+ for test in UnittestTestCase(obj)(): |
yield test |
# TODO(iannucci): Make this compatible with the awful load_tests hack? |