summaryrefslogtreecommitdiff
path: root/tests/test_execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-10-11 06:39:25 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-10-11 06:39:25 -0400
commitd3f46d2cc5d9fe6c30b31ffe7b268fb7a3addcda (patch)
treee8d874014d40cbb2194b4dff3453670e43e6e56a /tests/test_execfile.py
parentbcff84fb55d03643bf0a182d79a5ac8e809ec457 (diff)
downloadpython-coveragepy-git-d3f46d2cc5d9fe6c30b31ffe7b268fb7a3addcda.tar.gz
test: add a test of hash-based pyc files
Diffstat (limited to 'tests/test_execfile.py')
-rw-r--r--tests/test_execfile.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/test_execfile.py b/tests/test_execfile.py
index 5c01f892..b1306233 100644
--- a/tests/test_execfile.py
+++ b/tests/test_execfile.py
@@ -8,6 +8,7 @@ import json
import os
import os.path
import pathlib
+import py_compile
import re
import pytest
@@ -105,7 +106,7 @@ class RunFileTest(CoverageTest):
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")
@@ -116,7 +117,7 @@ class RunPycFileTest(CoverageTest):
doit()
""")
- compileall.compile_dir(".", quiet=True)
+ compileall.compile_dir(".", quiet=True, **kwargs)
os.remove("compiled.py")
# Find the .pyc file!
@@ -149,6 +150,12 @@ class RunPycFileTest(CoverageTest):
# 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}'")