annotate Lib/test/test_datetime.py @ 73807:1efefeda00a7 3.2

#8414: add more tests for "assert". Initial patch by Gregory Nofi.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 02 Dec 2011 18:22:52 +0200
parents dc245d681901
children 01e5d0771824
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63184
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
1 import unittest
61996
cac00cbbe770 Merged revisions 81556 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 61953
diff changeset
2 import sys
63184
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
3 from test.support import import_fresh_module, run_unittest
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
4 TESTS = 'test.datetimetester'
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
5 # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
6 # XXX: but it does not, so we have to save and restore it ourselves.
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
7 save_sys_modules = sys.modules.copy()
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
8 try:
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
9 pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
10 blocked=['_datetime'])
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
11 fast_tests = import_fresh_module(TESTS, fresh=['datetime',
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
12 '_datetime', '_strptime'])
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
13 finally:
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
14 sys.modules.clear()
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
15 sys.modules.update(save_sys_modules)
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
16 test_modules = [pure_tests, fast_tests]
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
17 test_suffixes = ["_Pure", "_Fast"]
26673
5b715cad34d0 datetime escapes the sandbox. The Windows build is all set. I leave it
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
18
63184
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
19 for module, suffix in zip(test_modules, test_suffixes):
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
20 for name, cls in module.__dict__.items():
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
21 if isinstance(cls, type) and issubclass(cls, unittest.TestCase):
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
22 name += suffix
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
23 cls.__name__ = name
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
24 globals()[name] = cls
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
25 def setUp(self, module=module, setup=cls.setUp):
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
26 self._save_sys_modules = sys.modules.copy()
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
27 sys.modules[TESTS] = module
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
28 sys.modules['datetime'] = module.datetime_module
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
29 sys.modules['_strptime'] = module._strptime
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
30 setup(self)
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
31 def tearDown(self, teardown=cls.tearDown):
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
32 teardown(self)
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
33 sys.modules.clear()
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
34 sys.modules.update(self._save_sys_modules)
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
35 cls.setUp = setUp
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
36 cls.tearDown = tearDown
33498
abbdbba56a8b SF bug #1028306: date-datetime comparison
Tim Peters <tim.peters@gmail.com>
parents: 32388
diff changeset
37
26673
5b715cad34d0 datetime escapes the sandbox. The Windows build is all set. I leave it
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
38 def test_main():
63184
afdb53323065 Issue #7989: Added pure python implementation of the datetime module.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62837
diff changeset
39 run_unittest(__name__)
26673
5b715cad34d0 datetime escapes the sandbox. The Windows build is all set. I leave it
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
40
5b715cad34d0 datetime escapes the sandbox. The Windows build is all set. I leave it
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
41 if __name__ == "__main__":
5b715cad34d0 datetime escapes the sandbox. The Windows build is all set. I leave it
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
42 test_main()