| OLD | NEW |
| 1 """Supporting definitions for the Python regression tests.""" | 1 """Supporting definitions for the Python regression tests.""" |
| 2 | 2 |
| 3 if __name__ != 'test.support': | 3 if __name__ != 'test.support': |
| 4 raise ImportError('support must be imported from the test package') | 4 raise ImportError('support must be imported from the test package') |
| 5 | 5 |
| 6 import contextlib | 6 import contextlib |
| 7 import errno | 7 import errno |
| 8 import functools | 8 import functools |
| 9 import gc | 9 import gc |
| 10 import socket | 10 import socket |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 elif len(result.failures) == 1 and not result.errors: | 1263 elif len(result.failures) == 1 and not result.errors: |
| 1264 err = result.failures[0][1] | 1264 err = result.failures[0][1] |
| 1265 else: | 1265 else: |
| 1266 err = "multiple errors occurred" | 1266 err = "multiple errors occurred" |
| 1267 if not verbose: err += "; run in verbose mode for details" | 1267 if not verbose: err += "; run in verbose mode for details" |
| 1268 raise TestFailed(err) | 1268 raise TestFailed(err) |
| 1269 | 1269 |
| 1270 | 1270 |
| 1271 def run_unittest(*classes): | 1271 def run_unittest(*classes): |
| 1272 """Run tests from unittest.TestCase-derived classes.""" | 1272 """Run tests from unittest.TestCase-derived classes.""" |
| 1273 regexes = run_unittest.regexes |
| 1274 if regexes: |
| 1275 def filter_test(name): |
| 1276 return any(regex.search(name) for regex in regexes) |
| 1277 else: |
| 1278 filter_test = None |
| 1273 valid_types = (unittest.TestSuite, unittest.TestCase) | 1279 valid_types = (unittest.TestSuite, unittest.TestCase) |
| 1274 suite = unittest.TestSuite() | 1280 suite = unittest.TestSuite() |
| 1275 for cls in classes: | 1281 for cls in classes: |
| 1276 if isinstance(cls, str): | 1282 if isinstance(cls, str): |
| 1277 if cls in sys.modules: | 1283 if cls in sys.modules: |
| 1278 suite.addTest(unittest.findTestCases(sys.modules[cls])) | 1284 suite.addTest(unittest.findTestCases(sys.modules[cls], filter=fi
lter_test)) |
| 1279 else: | 1285 else: |
| 1280 raise ValueError("str arguments must be keys in sys.modules") | 1286 raise ValueError("str arguments must be keys in sys.modules") |
| 1281 elif isinstance(cls, valid_types): | 1287 elif isinstance(cls, valid_types): |
| 1282 suite.addTest(cls) | 1288 suite.addTest(cls) |
| 1283 else: | 1289 else: |
| 1284 suite.addTest(unittest.makeSuite(cls)) | 1290 suite.addTest(unittest.makeSuite(cls, filter=filter_test)) |
| 1285 _run_suite(suite) | 1291 _run_suite(suite) |
| 1292 # List of regex objects used to filter the tests by their function name. |
| 1293 # An empty list means that all tests are used. |
| 1294 run_unittest.regexes = [] |
| 1286 | 1295 |
| 1287 | 1296 |
| 1288 #======================================================================= | 1297 #======================================================================= |
| 1289 # doctest driver. | 1298 # doctest driver. |
| 1290 | 1299 |
| 1291 def run_doctest(module, verbosity=None): | 1300 def run_doctest(module, verbosity=None): |
| 1292 """Run doctest on the given module. Return (#failures, #tests). | 1301 """Run doctest on the given module. Return (#failures, #tests). |
| 1293 | 1302 |
| 1294 If optional argument verbosity is not specified (or is None), pass | 1303 If optional argument verbosity is not specified (or is None), pass |
| 1295 support's belief about verbosity on to doctest. Else doctest's | 1304 support's belief about verbosity on to doctest. Else doctest's |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 def cleanup(): | 1606 def cleanup(): |
| 1598 if attr_is_local: | 1607 if attr_is_local: |
| 1599 setattr(object_to_patch, attr_name, old_value) | 1608 setattr(object_to_patch, attr_name, old_value) |
| 1600 else: | 1609 else: |
| 1601 delattr(object_to_patch, attr_name) | 1610 delattr(object_to_patch, attr_name) |
| 1602 | 1611 |
| 1603 test_instance.addCleanup(cleanup) | 1612 test_instance.addCleanup(cleanup) |
| 1604 | 1613 |
| 1605 # actually override the attribute | 1614 # actually override the attribute |
| 1606 setattr(object_to_patch, attr_name, new_value) | 1615 setattr(object_to_patch, attr_name, new_value) |
| OLD | NEW |