ยปCore Development>Code coverage>Lib/test/test_datetime.py

Python code coverage for Lib/test/test_datetime.py

#countcontent
1n/aimport unittest
2n/aimport sys
3n/a
4n/afrom test.support import import_fresh_module, run_unittest
5n/a
6n/aTESTS = 'test.datetimetester'
7n/a
8n/atry:
9n/a pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
10n/a blocked=['_datetime'])
11n/a fast_tests = import_fresh_module(TESTS, fresh=['datetime',
12n/a '_datetime', '_strptime'])
13n/afinally:
14n/a # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
15n/a # XXX: but it does not, so we have to cleanup ourselves.
16n/a for modname in ['datetime', '_datetime', '_strptime']:
17n/a sys.modules.pop(modname, None)
18n/atest_modules = [pure_tests, fast_tests]
19n/atest_suffixes = ["_Pure", "_Fast"]
20n/a# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
21n/a# not believe this, but in spite of all the sys.modules trickery running a _Pure
22n/a# test last will leave a mix of pure and native datetime stuff lying around.
23n/atest_classes = []
24n/a
25n/afor module, suffix in zip(test_modules, test_suffixes):
26n/a test_classes = []
27n/a for name, cls in module.__dict__.items():
28n/a if not isinstance(cls, type):
29n/a continue
30n/a if issubclass(cls, unittest.TestCase):
31n/a test_classes.append(cls)
32n/a elif issubclass(cls, unittest.TestSuite):
33n/a suit = cls()
34n/a test_classes.extend(type(test) for test in suit)
35n/a for cls in test_classes:
36n/a cls.__name__ = name + suffix
37n/a @classmethod
38n/a def setUpClass(cls_, module=module):
39n/a cls_._save_sys_modules = sys.modules.copy()
40n/a sys.modules[TESTS] = module
41n/a sys.modules['datetime'] = module.datetime_module
42n/a sys.modules['_strptime'] = module._strptime
43n/a @classmethod
44n/a def tearDownClass(cls_):
45n/a sys.modules.clear()
46n/a sys.modules.update(cls_._save_sys_modules)
47n/a cls.setUpClass = setUpClass
48n/a cls.tearDownClass = tearDownClass
49n/a
50n/adef test_main():
51n/a run_unittest(*test_classes)
52n/a
53n/aif __name__ == "__main__":
54n/a test_main()