~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_datetime.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import unittest
2
2
import sys
3
3
from test.support import import_fresh_module, run_unittest
 
4
 
4
5
TESTS = 'test.datetimetester'
 
6
 
5
7
# XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
6
8
# XXX: but it does not, so we have to save and restore it ourselves.
7
9
save_sys_modules = sys.modules.copy()
15
17
    sys.modules.update(save_sys_modules)
16
18
test_modules = [pure_tests, fast_tests]
17
19
test_suffixes = ["_Pure", "_Fast"]
 
20
# XXX(gb) First run all the _Pure tests, then all the _Fast tests.  You might
 
21
# not believe this, but in spite of all the sys.modules trickery running a _Pure
 
22
# test last will leave a mix of pure and native datetime stuff lying around.
 
23
test_classes = []
18
24
 
19
25
for module, suffix in zip(test_modules, test_suffixes):
20
26
    for name, cls in module.__dict__.items():
21
 
        if isinstance(cls, type) and issubclass(cls, unittest.TestCase):
22
 
            name += suffix
23
 
            cls.__name__ = name
24
 
            globals()[name] = cls
25
 
            def setUp(self, module=module, setup=cls.setUp):
26
 
                self._save_sys_modules = sys.modules.copy()
27
 
                sys.modules[TESTS] = module
28
 
                sys.modules['datetime'] = module.datetime_module
29
 
                sys.modules['_strptime'] = module._strptime
30
 
                setup(self)
31
 
            def tearDown(self, teardown=cls.tearDown):
32
 
                teardown(self)
33
 
                sys.modules.clear()
34
 
                sys.modules.update(self._save_sys_modules)
35
 
            cls.setUp = setUp
36
 
            cls.tearDown = tearDown
 
27
        if not (isinstance(cls, type) and issubclass(cls, unittest.TestCase)):
 
28
            continue
 
29
        cls.__name__ = name + suffix
 
30
        @classmethod
 
31
        def setUpClass(cls_, module=module):
 
32
            cls_._save_sys_modules = sys.modules.copy()
 
33
            sys.modules[TESTS] = module
 
34
            sys.modules['datetime'] = module.datetime_module
 
35
            sys.modules['_strptime'] = module._strptime
 
36
        @classmethod
 
37
        def tearDownClass(cls_):
 
38
            sys.modules.clear()
 
39
            sys.modules.update(cls_._save_sys_modules)
 
40
        cls.setUpClass = setUpClass
 
41
        cls.tearDownClass = tearDownClass
 
42
        test_classes.append(cls)
37
43
 
38
44
def test_main():
39
 
    run_unittest(__name__)
 
45
    run_unittest(*test_classes)
40
46
 
41
47
if __name__ == "__main__":
42
48
    test_main()