summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_import.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-01-01 03:40:42 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-01-01 03:40:42 (GMT)
commit1f7df8f2070391f28391e3594580c07e11b6b32b (patch)
treeec03dfe4f71df3840232731145b8f6736fc6a314 /Lib/test/test_import.py
parentb25d611f8d9140e83acbfffb6b0579939c88c033 (diff)
parent10e93a6d40502e100c68090730e0b3190df97854 (diff)
downloadcpython-1f7df8f2070391f28391e3594580c07e11b6b32b.zip
cpython-1f7df8f2070391f28391e3594580c07e11b6b32b.tar.gz
cpython-1f7df8f2070391f28391e3594580c07e11b6b32b.tar.bz2
merge heads
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r--Lib/test/test_import.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index edd1869..ea50d34 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -5,6 +5,7 @@ import os
import py_compile
import random
import stat
+import struct
import sys
import unittest
import textwrap
@@ -350,6 +351,46 @@ class ImportTests(unittest.TestCase):
del sys.path[0]
remove_files(TESTFN)
+ def test_pyc_mtime(self):
+ # Test for issue #13863: .pyc timestamp sometimes incorrect on Windows.
+ sys.path.insert(0, os.curdir)
+ try:
+ # Jan 1, 2012; Jul 1, 2012.
+ mtimes = 1325376000, 1341100800
+
+ # Different names to avoid running into import caching.
+ tails = "spam", "eggs"
+ for mtime, tail in zip(mtimes, tails):
+ module = TESTFN + tail
+ source = module + ".py"
+ compiled = source + ('c' if __debug__ else 'o')
+
+ # Create a new Python file with the given mtime.
+ with open(source, 'w') as f:
+ f.write("# Just testing\nx=1, 2, 3\n")
+ os.utime(source, (mtime, mtime))
+
+ # Generate the .pyc/o file; if it couldn't be created
+ # for some reason, skip the test.
+ m = __import__(module)
+ if not os.path.exists(compiled):
+ unlink(source)
+ self.skipTest("Couldn't create .pyc/.pyo file.")
+
+ # Actual modification time of .py file.
+ mtime1 = int(os.stat(source).st_mtime) & 0xffffffff
+
+ # mtime that was encoded in the .pyc file.
+ with open(compiled, 'rb') as f:
+ mtime2 = struct.unpack('<L', f.read(8)[4:])[0]
+
+ unlink(compiled)
+ unlink(source)
+
+ self.assertEqual(mtime1, mtime2)
+ finally:
+ sys.path.pop(0)
+
class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points