| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from expect_tests.type_definitions import ( | 7 from expect_tests.type_definitions import ( |
| 8 Test, Result, MultiTest, FuncCall, Bind) | 8 Test, Result, MultiTest, FuncCall, Bind) |
| 9 | 9 |
| 10 from expect_tests.util import covers | 10 from expect_tests.util import covers |
| 11 | 11 |
| 12 | 12 |
| 13 def _SetUpClass(test_class): | 13 def _SetUpClass(test_class): |
| 14 inst = test_class('__init__') | 14 inst = test_class('__init__') |
| 15 inst.setUpClass() | 15 inst.setUpClass() |
| 16 return inst | 16 return inst |
| 17 | 17 |
| 18 | 18 |
| 19 def _TearDownClass(test_class_inst): | 19 def _TearDownClass(test_class_inst): |
| 20 test_class_inst.tearDownClass() | 20 test_class_inst.tearDownClass() |
| 21 | 21 |
| 22 | 22 |
| 23 def _RunTestCaseSingle(test_case, test_name, test_instance=None): | 23 def _RunTestCaseSingle(test_case, test_name, test_instance=None): |
| 24 # The hack is so that unittest.TestCase has something to pretend is the | 24 # The hack is so that unittest.TestCase has something to pretend is the |
| 25 # test method without the BS of wrapping each method in a new TestCase | 25 # test method without the BS of wrapping each method in a new TestCase |
| 26 # class... | 26 # class... |
| 27 test_instance = test_instance or test_case('__init__') | 27 test_instance = test_instance or test_case('__init__') |
| 28 test_instance.setUp() | 28 test_instance.setUp() |
| 29 test_instance._test_failed_with_exception = False |
| 29 try: | 30 try: |
| 30 return Result(getattr(test_instance, test_name)()) | 31 return Result(getattr(test_instance, test_name)()) |
| 32 except KeyboardInterrupt: |
| 33 raise |
| 34 except: |
| 35 test_instance._test_failed_with_exception = True |
| 36 raise |
| 31 finally: | 37 finally: |
| 32 test_instance.tearDown() | 38 test_instance.tearDown() |
| 33 | 39 |
| 34 | 40 |
| 35 def UnittestTestCase(test_case): | 41 def UnittestTestCase(test_case): |
| 36 """Yield a MultiTest or multiple Test instances for the unittest.TestCase | 42 """Yield a MultiTest or multiple Test instances for the unittest.TestCase |
| 37 derived |test_case|. | 43 derived |test_case|. |
| 38 | 44 |
| 39 If the TestCase has a field `__expect_tests_serial__` defined to be True, then | 45 If the TestCase has a field `__expect_tests_serial__` defined to be True, then |
| 40 all test methods in the TestCase will be guaranteed to run in a single process | 46 all test methods in the TestCase will be guaranteed to run in a single process |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 contains zero or more unittest.TestCase implementations. | 105 contains zero or more unittest.TestCase implementations. |
| 100 | 106 |
| 101 @type test_module: types.ModuleType | 107 @type test_module: types.ModuleType |
| 102 """ | 108 """ |
| 103 for name in dir(test_module): | 109 for name in dir(test_module): |
| 104 obj = getattr(test_module, name) | 110 obj = getattr(test_module, name) |
| 105 if _is_unittest(obj): | 111 if _is_unittest(obj): |
| 106 for test in UnittestTestCase(obj)(): | 112 for test in UnittestTestCase(obj)(): |
| 107 yield test | 113 yield test |
| 108 # TODO(iannucci): Make this compatible with the awful load_tests hack? | 114 # TODO(iannucci): Make this compatible with the awful load_tests hack? |
| OLD | NEW |