Skip to content

Commit d3f46d2

Browse files
committed
test: add a test of hash-based pyc files
1 parent bcff84f commit d3f46d2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/test_execfile.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import os.path
1010
import pathlib
11+
import py_compile
1112
import re
1213

1314
import pytest
@@ -105,7 +106,7 @@ def test_directory_without_main(self):
105106
class RunPycFileTest(CoverageTest):
106107
"""Test cases for `run_python_file`."""
107108

108-
def make_pyc(self):
109+
def make_pyc(self, **kwargs):
109110
"""Create a .pyc file, and return the path to it."""
110111
if env.JYTHON:
111112
pytest.skip("Can't make .pyc files on Jython")
@@ -116,7 +117,7 @@ def doit():
116117
117118
doit()
118119
""")
119-
compileall.compile_dir(".", quiet=True)
120+
compileall.compile_dir(".", quiet=True, **kwargs)
120121
os.remove("compiled.py")
121122

122123
# Find the .pyc file!
@@ -149,6 +150,12 @@ def test_running_pyc_from_wrong_python(self):
149150
# In some environments, the pycfile persists and pollutes another test.
150151
os.remove(pycfile)
151152

153+
@pytest.mark.skipif(not env.PYBEHAVIOR.hashed_pyc_pep552, reason="No hashed .pyc here")
154+
def test_running_hashed_pyc(self):
155+
pycfile = self.make_pyc(invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH)
156+
run_python_file([pycfile])
157+
assert self.stdout() == "I am here!\n"
158+
152159
def test_no_such_pyc_file(self):
153160
path = python_reported_file('xyzzy.pyc')
154161
msg = re.escape(f"No file to run: '{path}'")

0 commit comments

Comments
 (0)