diff options
-rw-r--r-- | Makefile | 27 | ||||
-rwxr-xr-x | ci/manylinux.sh | 5 | ||||
-rw-r--r-- | coverage/execfile.py | 2 | ||||
-rw-r--r-- | tests/test_execfile.py | 20 |
4 files changed, 39 insertions, 15 deletions
@@ -6,14 +6,16 @@ default: @echo "* No default action *" -clean: - -pip uninstall -y coverage - -rm -f *.pyd */*.pyd +clean_platform: ## Remove files that clash across platforms. -rm -f *.so */*.so - -rm -rf build coverage.egg-info dist htmlcov -rm -rf __pycache__ */__pycache__ */*/__pycache__ */*/*/__pycache__ */*/*/*/__pycache__ */*/*/*/*/__pycache__ -rm -f *.pyc */*.pyc */*/*.pyc */*/*/*.pyc */*/*/*/*.pyc */*/*/*/*/*.pyc -rm -f *.pyo */*.pyo */*/*.pyo */*/*/*.pyo */*/*/*/*.pyo */*/*/*/*/*.pyo + +clean: clean_platform ## Remove artifacts of test execution, installation, etc. + -pip uninstall -y coverage + -rm -f *.pyd */*.pyd + -rm -rf build coverage.egg-info dist htmlcov -rm -f *.bak */*.bak */*/*.bak */*/*/*.bak */*/*/*/*.bak */*/*/*/*/*.bak -rm -f *$$py.class */*$$py.class */*/*$$py.class */*/*/*$$py.class */*/*/*/*$$py.class */*/*/*/*/*$$py.class -rm -f coverage/*,cover @@ -30,7 +32,7 @@ clean: -rm -rf $$TMPDIR/coverage_test -make -C tests/gold/html clean -sterile: clean +sterile: clean ## Remove all non-controlled content, even if expensive. -rm -rf .tox* -docker image rm -f quay.io/pypa/manylinux1_i686 quay.io/pypa/manylinux1_x86_64 @@ -67,6 +69,17 @@ pysmoke: # Run tests with the Python tracer in the lowest supported Python versions. COVERAGE_NO_CTRACER=1 tox -q -e py27,py35 -- $(PYTEST_SMOKE_ARGS) +DOCKER_RUN = docker run -it --init --rm -v `pwd`:/io +RUN_MANYLINUX_X86 = $(DOCKER_RUN) quay.io/pypa/manylinux1_x86_64 /io/ci/manylinux.sh +RUN_MANYLINUX_I686 = $(DOCKER_RUN) quay.io/pypa/manylinux1_i686 /io/ci/manylinux.sh + +testmanylinux: + # The Linux .pyc files clash with the host's because of file path + # changes, so clean them before and after running tests. + make clean_platform + $(RUN_MANYLINUX_X86) test $(ARGS) + make clean_platform + # Coverage measurement of coverage.py itself (meta-coverage). See metacov.ini # for details. @@ -85,8 +98,8 @@ wheel: tox -c tox_wheels.ini $(ARGS) manylinux: - docker run -it --init --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/ci/manylinux.sh build - docker run -it --init --rm -v `pwd`:/io quay.io/pypa/manylinux1_i686 /io/ci/manylinux.sh build + $(RUN_MANYLINUX_X86) build + $(RUN_MANYLINUX_I686) build kit_upload: twine upload --verbose dist/* diff --git a/ci/manylinux.sh b/ci/manylinux.sh index 57439898..31f3bed8 100755 --- a/ci/manylinux.sh +++ b/ci/manylinux.sh @@ -35,10 +35,11 @@ elif [[ $action == "test" ]]; then done # Install packages and test - TOXBIN=/opt/python/cp27-cp27m/bin - "$TOXBIN/pip" install -r /io/requirements/ci.pip + TOXBIN=/opt/python/cp36-cp36m/bin + "$TOXBIN/pip" install -r /io/requirements/tox.pip cd /io + export PYTHONPYCACHEPREFIX=/opt/pyc TOXWORKDIR=.tox_linux "$TOXBIN/tox" "$@" || true cd ~ diff --git a/coverage/execfile.py b/coverage/execfile.py index ce7c9dd4..828df68e 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -292,7 +292,7 @@ def make_code_from_pyc(filename): # match or we won't run the file. magic = fpyc.read(4) if magic != PYC_MAGIC_NUMBER: - raise NoCode("Bad magic number in .pyc file") + raise NoCode("Bad magic number in .pyc file: {} != {}".format(magic, PYC_MAGIC_NUMBER)) date_based = True if env.PYBEHAVIOR.hashed_pyc_pep552: diff --git a/tests/test_execfile.py b/tests/test_execfile.py index 340df4cf..7ced605a 100644 --- a/tests/test_execfile.py +++ b/tests/test_execfile.py @@ -4,10 +4,12 @@ """Tests for coverage.execfile""" import compileall +import fnmatch import json import os import os.path import re +import sys from coverage import env from coverage.backward import binary_bytes @@ -102,7 +104,7 @@ class RunPycFileTest(CoverageTest): """Test cases for `run_python_file`.""" def make_pyc(self): # pylint: disable=inconsistent-return-statements - """Create a .pyc file, and return the relative path to it.""" + """Create a .pyc file, and return the path to it.""" if env.JYTHON: self.skipTest("Can't make .pyc files on Jython") @@ -116,10 +118,15 @@ class RunPycFileTest(CoverageTest): os.remove("compiled.py") # Find the .pyc file! - for there, _, files in os.walk("."): # pragma: part covered - for f in files: - if f.endswith(".pyc"): # pragma: part covered - return os.path.join(there, f) + roots = ["."] + prefix = getattr(sys, "pycache_prefix", None) + if prefix: + roots.append(prefix) + for root in roots: # pragma: part covered + for there, _, files in os.walk(root): # pragma: part covered + for fname in files: + if fnmatch.fnmatch(fname, "compiled*.pyc"): + return os.path.join(there, fname) def test_running_pyc(self): pycfile = self.make_pyc() @@ -145,6 +152,9 @@ class RunPycFileTest(CoverageTest): with self.assertRaisesRegex(NoCode, "Bad magic number in .pyc file"): run_python_file([pycfile]) + # In some environments, the pycfile persists and pollutes another test. + os.remove(pycfile) + def test_no_such_pyc_file(self): with self.assertRaisesRegex(NoCode, "No file to run: 'xyzzy.pyc'"): run_python_file(["xyzzy.pyc"]) |