summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_zipimport.py16
-rw-r--r--Lib/zipimport.py2
2 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index d4f619e..2af8689 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -6,6 +6,7 @@ import importlib.util
import struct
import time
import unittest
+import unittest.mock
from test import support
@@ -204,6 +205,21 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
self.assertEqual(mod.state, 'old')
self.doTest(None, files, TESTMOD, call=check)
+ @unittest.mock.patch('_imp.check_hash_based_pycs', 'always')
+ def test_checked_hash_based_change_pyc(self):
+ source = b"state = 'old'"
+ source_hash = importlib.util.source_hash(source)
+ bytecode = importlib._bootstrap_external._code_to_hash_pyc(
+ compile(source, "???", "exec"),
+ source_hash,
+ False,
+ )
+ files = {TESTMOD + ".py": (NOW, "state = 'new'"),
+ TESTMOD + ".pyc": (NOW - 20, bytecode)}
+ def check(mod):
+ self.assertEqual(mod.state, 'new')
+ self.doTest(None, files, TESTMOD, call=check)
+
def testEmptyPy(self):
files = {TESTMOD + ".py": (NOW, "")}
self.doTest(None, files, TESTMOD)
diff --git a/Lib/zipimport.py b/Lib/zipimport.py
index fd917c1..5ef0a17 100644
--- a/Lib/zipimport.py
+++ b/Lib/zipimport.py
@@ -608,7 +608,7 @@ def _unmarshal_code(self, pathname, fullpath, fullname, data):
)
try:
- _boostrap_external._validate_hash_pyc(
+ _bootstrap_external._validate_hash_pyc(
data, source_hash, fullname, exc_details)
except ImportError:
return None