This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients malin, misho88, serhiy.storchaka, twouters, xtreak, zach.ware
Date 2019-12-13.06:08:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576217327.97.0.990583292951.issue39033@roundup.psfhosted.org>
In-reply-to
Content
A possible test case to trigger this code path based on testUncheckedHashBasedPyc would be as below. check_hash_based_pycs can be patched to be "always" so that the hash is validated using _bootstrap_external._validate_hash_pyc. The difference between "state = old" for pyc and "state = new" in py would ensure the hashes are different to raise ImportError expected and the test picks up state = new as the updated source code. Without fixing the typo trying to make hash validation would throw NameError.


@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)
History
Date User Action Args
2019-12-13 06:08:48xtreaksetrecipients: + xtreak, twouters, zach.ware, serhiy.storchaka, malin, misho88
2019-12-13 06:08:47xtreaksetmessageid: <1576217327.97.0.990583292951.issue39033@roundup.psfhosted.org>
2019-12-13 06:08:47xtreaklinkissue39033 messages
2019-12-13 06:08:47xtreakcreate