summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-01-24 16:45:50 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-01-24 16:45:50 (GMT)
commitabaf89b2be32db1deae32cbdf0645a4be65c6297 (patch)
tree966393e84f1693146f2dd81d2fbe111911ea3d10 /Lib/importlib/test
parenta10999d55c93aa7bccc2b87ca81a336b20459bcd (diff)
parent2be60afb7e0753c1bd5c297960cf8686a1ec7e1e (diff)
downloadcpython-abaf89b2be32db1deae32cbdf0645a4be65c6297.zip
cpython-abaf89b2be32db1deae32cbdf0645a4be65c6297.tar.gz
cpython-abaf89b2be32db1deae32cbdf0645a4be65c6297.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/importlib/test')
-rw-r--r--Lib/importlib/test/source/test_file_loader.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py
index 0809077..e967e08 100644
--- a/Lib/importlib/test/source/test_file_loader.py
+++ b/Lib/importlib/test/source/test_file_loader.py
@@ -123,6 +123,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):