diff options
author | Karthikeyan Singaravelan <tir.karthi@gmail.com> | 2020-01-14 11:39:19 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-01-14 11:39:19 (GMT) |
commit | 9955f33cdbf27de270038dfbad37d15b160ecca2 (patch) | |
tree | 8ff7bf457eecc3c74dfe263cb1b0c48894e2e0e9 /Lib/test | |
parent | 9362f8526e42157baf27df982b16f23f212c3c3a (diff) | |
download | cpython-9955f33cdbf27de270038dfbad37d15b160ecca2.zip cpython-9955f33cdbf27de270038dfbad37d15b160ecca2.tar.gz cpython-9955f33cdbf27de270038dfbad37d15b160ecca2.tar.bz2 |
[3.8] bpo-39033: Fix NameError in zipimport during hash validation (GH-17588) (GH-17642)
Fix `NameError` in `zipimport` during hash validation and add a regression test.
(cherry picked from commit 79f02fee1a542c440fd906fd54154c73fc0f8235)
https://bugs.python.org/issue39033
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_zipimport.py | 16 |
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) |