summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipimport.py
diff options
context:
space:
mode:
authorXtreak <tir.karthi@gmail.com>2019-12-15 23:34:12 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2019-12-15 23:34:12 (GMT)
commit79f02fee1a542c440fd906fd54154c73fc0f8235 (patch)
tree33368ca08ce4e6560eccfcf0fa173a2ad19344e1 /Lib/test/test_zipimport.py
parentd587272fe3b0fcad2f23a490e76f9f82ca7d64ef (diff)
downloadcpython-79f02fee1a542c440fd906fd54154c73fc0f8235.zip
cpython-79f02fee1a542c440fd906fd54154c73fc0f8235.tar.gz
cpython-79f02fee1a542c440fd906fd54154c73fc0f8235.tar.bz2
bpo-39033: Fix NameError in zipimport during hash validation (GH-17588)
Patch by Karthikeyan Singaravelan.
Diffstat (limited to 'Lib/test/test_zipimport.py')
-rw-r--r--Lib/test/test_zipimport.py16
1 files changed, 16 insertions, 0 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)