[Python-Dev] Python equivalents in stdlib Was: Include datetime.py in stdlib or not?

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Jul 13 04:30:51 CEST 2010


On Thu, Jul 8, 2010 at 9:44 PM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
..
> and it still requires that '_pickle' is disabled to pass pickle tests.
>

I have found the problem in test_datetime.  Restoring sys.modules has
to be done in-place.  With this fix, test_datetime looks as follows:

=====
import unittest
import sys
from test.support import import_fresh_module, run_unittest
TESTS = 'test.datetimetester'
pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
                                 blocked=['_datetime'])
fast_tests = import_fresh_module(TESTS, fresh=['datetime',
                                               '_datetime', '_strptime'])

test_modules = [pure_tests, fast_tests]
test_suffixes = ["_Pure", "_Fast"]

for module, suffix in zip(test_modules, test_suffixes):
    for name, cls in module.__dict__.items():
	if isinstance(cls, type) and issubclass(cls, unittest.TestCase):
            name += suffix
            cls.__name__ = name
            globals()[name] = cls
            def setUp(self, module=module, setup=cls.setUp):
		self._save_sys_modules = sys.modules.copy()
		sys.modules[TESTS] = module
		sys.modules['datetime'] = module.datetime_module
		sys.modules['_strptime'] = module.datetime_module._strptime
		setup(self)
            def tearDown(self, teardown=cls.tearDown):
		teardown(self)
		sys.modules.__init__(self._save_sys_modules)
            cls.setUp = setUp
            cls.tearDown = tearDown

def test_main():
    run_unittest(__name__)

if __name__ == "__main__":
    test_main()
=====

I think this is as good as it gets.   I am going to update the patch
at http://bugs.python.org/issue7989 .


More information about the Python-Dev mailing list