summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_import.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-01-13 17:52:16 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-01-13 17:52:16 (GMT)
commit5136ac0ca21a05691978df8d0650f902c8ca3463 (patch)
tree4b5569dad3f1b36f115c673602dde6ff49eae5e0 /Lib/test/test_import.py
parent1f918c1480a1566b774391bbc4ddf1d4153965a1 (diff)
downloadcpython-5136ac0ca21a05691978df8d0650f902c8ca3463.zip
cpython-5136ac0ca21a05691978df8d0650f902c8ca3463.tar.gz
cpython-5136ac0ca21a05691978df8d0650f902c8ca3463.tar.bz2
Issue #13645: pyc files now contain the size of the corresponding source
code, to avoid timestamp collisions (especially on filesystems with a low timestamp resolution) when checking for freshness of the bytecode.
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r--Lib/test/test_import.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 9f80b70..e4d5332 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -380,7 +380,7 @@ func_filename = func.__code__.co_filename
def test_foreign_code(self):
py_compile.compile(self.file_name)
with open(self.compiled_name, "rb") as f:
- header = f.read(8)
+ header = f.read(12)
code = marshal.load(f)
constants = list(code.co_consts)
foreign_code = test_main.__code__
@@ -644,6 +644,16 @@ class PycacheTests(unittest.TestCase):
self.assertEqual(sys.modules['pep3147.foo'].__cached__,
os.path.join(os.curdir, foo_pyc))
+ def test_recompute_pyc_same_second(self):
+ # Even when the source file doesn't change timestamp, a change in
+ # source size is enough to trigger recomputation of the pyc file.
+ __import__(TESTFN)
+ unload(TESTFN)
+ with open(self.source, 'a') as fp:
+ print("x = 5", file=fp)
+ m = __import__(TESTFN)
+ self.assertEqual(m.x, 5)
+
class RelativeImportFromImportlibTests(test_relative_imports.RelativeImports):