Skip to content

Commit

Permalink
test: add a test of hash-based pyc files
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 11, 2021
1 parent bcff84f commit d3f46d2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/test_execfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import os.path
import pathlib
import py_compile
import re

import pytest
Expand Down Expand Up @@ -105,7 +106,7 @@ def test_directory_without_main(self):
class RunPycFileTest(CoverageTest):
"""Test cases for `run_python_file`."""

def make_pyc(self):
def make_pyc(self, **kwargs):
"""Create a .pyc file, and return the path to it."""
if env.JYTHON:
pytest.skip("Can't make .pyc files on Jython")
Expand All @@ -116,7 +117,7 @@ def doit():
doit()
""")
compileall.compile_dir(".", quiet=True)
compileall.compile_dir(".", quiet=True, **kwargs)
os.remove("compiled.py")

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

@pytest.mark.skipif(not env.PYBEHAVIOR.hashed_pyc_pep552, reason="No hashed .pyc here")
def test_running_hashed_pyc(self):
pycfile = self.make_pyc(invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH)
run_python_file([pycfile])
assert self.stdout() == "I am here!\n"

def test_no_such_pyc_file(self):
path = python_reported_file('xyzzy.pyc')
msg = re.escape(f"No file to run: '{path}'")
Expand Down

0 comments on commit d3f46d2

Please sign in to comment.