diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-24 16:44:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-24 16:44:06 (GMT) |
commit | 2be60afb7e0753c1bd5c297960cf8686a1ec7e1e (patch) | |
tree | 59dc4e7152c3bc9141b6dc000f8c10b1384a3750 /Lib | |
parent | 7fa5a99b0693100077a556f05e3c6638b837389b (diff) | |
download | cpython-2be60afb7e0753c1bd5c297960cf8686a1ec7e1e.zip cpython-2be60afb7e0753c1bd5c297960cf8686a1ec7e1e.tar.gz cpython-2be60afb7e0753c1bd5c297960cf8686a1ec7e1e.tar.bz2 |
Issue #11235: Fix OverflowError when trying to import a source file whose modification time doesn't fit in a 32-bit timestamp.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/test/source/test_file_loader.py | 17 | ||||
-rw-r--r-- | Lib/test/test_import.py | 12 |
2 files changed, 29 insertions, 0 deletions
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py index de1c4d8..89990be 100644 --- a/Lib/importlib/test/source/test_file_loader.py +++ b/Lib/importlib/test/source/test_file_loader.py @@ -128,6 +128,23 @@ class SimpleTest(unittest.TestCase): pycache = os.path.dirname(imp.cache_from_source(file_path)) shutil.rmtree(pycache) + def test_timestamp_overflow(self): + # When a modification timestamp is larger than 2**32, it should be + # truncated rather than raise an OverflowError. + with source_util.create_modules('_temp') as mapping: + source = mapping['_temp'] + compiled = imp.cache_from_source(source) + with open(source, 'w') as f: + f.write("x = 5") + os.utime(source, (2 ** 33, 2 ** 33)) + loader = _bootstrap._SourceFileLoader('_temp', mapping['_temp']) + mod = loader.load_module('_temp') + # Sanity checks. + self.assertEqual(mod.__cached__, compiled) + self.assertEqual(mod.x, 5) + # The pyc file was created. + os.stat(compiled) + class BadBytecodeTest(unittest.TestCase): diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index c695757..33277d7 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -310,6 +310,18 @@ class ImportTests(unittest.TestCase): """)) script_helper.assert_python_ok(testfn) + def test_timestamp_overflow(self): + # A modification timestamp larger than 2**32 should not be a problem + # when importing a module (issue #11235). + source = TESTFN + ".py" + compiled = imp.cache_from_source(source) + with open(source, 'w') as f: + pass + os.utime(source, (2 ** 33, 2 ** 33)) + __import__(TESTFN) + # The pyc file was created. + os.stat(compiled) + class PycRewritingTests(unittest.TestCase): # Test that the `co_filename` attribute on code objects always points |