From c10465fa20aefbf49c28f9d527c1f0079bef76d0 Mon Sep 17 00:00:00 2001 From: Evan Kepner Date: Sun, 5 Jan 2020 09:32:00 -0500 Subject: [PATCH] cov4 test environment --- .travis.yml | 5 +++++ pytest.ini | 1 + tests/conftest.py | 8 ++------ tests/test_api.py | 4 ++-- tests/test_filters.py | 1 + tox.ini | 13 ++++++++----- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6530054..5eaf677 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,11 @@ matrix: name: "Python 3.8 core tests" env: TOXENV=py38 + # specific checks for coverage v4 support, coverage v5 is used by default elsewhere + - python: "3.8" + name: "Python 3.8 coverage v4 tests" + env: TOXENV=cov4 + # run pre-commit hooks checks # TODO: Python 3.8, pyenv global system 3.8 doesn't appear to work - python: "3.7" diff --git a/pytest.ini b/pytest.ini index a09f5d5..004d354 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,3 +3,4 @@ addopts = -ra -v --cov=mutatest markers = slow: slow tests, usually because pytest is running sub-trials on mutated temp caches. + coverage: tests that create mock coverage files for running Coverage v4 vs. v5 tests. diff --git a/tests/conftest.py b/tests/conftest.py index 4f02b3a..60d0e22 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -94,22 +94,18 @@ def write_cov_file(line_data: Dict[str, List[int]], fname: str) -> None: Returns: None - - Raises: - EnvironmentError: if Coverage version is not 4 or 5 """ if coverage.version_info[0] == 4: covdata = coverage.CoverageData() covdata.add_lines(line_data) covdata.write_file(fname) - if coverage.version_info[0] == 5: + else: + # assume coverage v 5 covdata = coverage.CoverageData(basename=fname) covdata.add_lines(line_data) covdata.write() - raise EnvironmentError(f"Coverage version is not supported: {coverage.version_info}") - #################################################################################################### # FILTERS: MOCK COVERAGE FILE FIXTURES diff --git a/tests/test_api.py b/tests/test_api.py index a1762b0..6cbd570 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -106,7 +106,7 @@ def test_mutate_ValueError_target(binop_file, mock_LocIdx): _ = genome.mutate(target_idx=mock_LocIdx, mutation_op=ast.Div, write_cache=False) -@pytest.mark.skipif(coverage.version_info[0] > 4, reason="Coverage version > 4.x") +@pytest.mark.coverage @pytest.mark.parametrize("filter_codes", [set(), ("bn",)], ids=["Filter Empty Set", "Filter BinOp"]) def test_covered_targets(filter_codes, binop_file, mock_binop_coverage_file): """Mock coverage file sets lines 6 and 10 (not 15) to be covered.""" @@ -253,7 +253,7 @@ def test_GenomeGroup_add_folder_with_exclusions(tmp_path): assert list(ggrp.keys())[0].name == expected -@pytest.mark.skipif(coverage.version_info[0] > 4, reason="Coverage version > 4.x") +@pytest.mark.coverage @pytest.mark.parametrize("filter_codes", [set(), ("bn",)], ids=["Filter Empty Set", "Filter BinOp"]) def test_GenomeGroup_covered_targets(filter_codes, binop_file, mock_binop_coverage_file): """Mock coverage file sets lines 6 and 10 (not 15) to be covered.""" diff --git a/tests/test_filters.py b/tests/test_filters.py index 362beb3..970828e 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -34,6 +34,7 @@ def test_unset_coverage_file(fn): _ = ccf.coverage_data +@pytest.mark.coverage @pytest.mark.parametrize( "invert, expected", [(False, [1, 2, 4]), (True, [3, 5])], diff --git a/tox.ini b/tox.ini index 8aa872b..799d60d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,10 @@ [tox] minversion = 3.7 -envlist = py37, py38, lint, typing, pypi-description, manifest, help, docs +envlist = py37, py38, lint, cov4, typing, pypi-description, manifest, help, docs [testenv] +# Baseline test environment for both Py 3.7 and 3.8 setenv = VIRTUALENV_NO_DOWNLOAD=1 extras = dev @@ -12,30 +13,33 @@ commands = python -m pytest --cov=mutatest {posargs} [testenv:help] +# Ensure no errors are raised from the help text display install_command = pip install --no-compile {opts} {packages} setenv = PYTHONWARNINGS=d commands = mutatest --help +[testenv:cov4] +# Test with coverage v4 specifically +commands = + pip install 'coverage<5.0' + pytest -m coverage [testenv:lint] skip_install = true deps = pre-commit commands = pre-commit run --all-files --verbose - [testenv:typing] skip_install = true deps = mypy commands = mypy --strict mutatest - [testenv:docs] deps = docs changedir = docs commands = sphinx-build -W -b html . _build - [testenv:pypi-description] skip_install = true deps = @@ -47,7 +51,6 @@ commands = pip wheel -w {envtmpdir}/build --no-deps . twine check {envtmpdir}/build/* - [testenv:manifest] deps = check-manifest skip_install = true