Repository: boxed/mutmut

Issue:
Mutmut doesn't work with Coverage 5.0
I really should have tested this with the beta. I just forgot about this feature of mutmut, sloppy!

Discussion:
boxed: Fantastic! Thanks!

Patch:
diff --git a/mutmut/__init__.py b/mutmut/__init__.py
index 4ee49c5..638b2b1 100644
--- a/mutmut/__init__.py
+++ b/mutmut/__init__.py
@@ -456,7 +456,7 @@ def should_exclude(context, config):
         covered_lines = config.covered_lines_by_filename[context.filename]
     except KeyError:
         if config.coverage_data is not None:
-            covered_lines = config.coverage_data.lines(os.path.abspath(context.filename))
+            covered_lines = config.coverage_data.get(os.path.abspath(context.filename))
             config.covered_lines_by_filename[context.filename] = covered_lines
         else:
             covered_lines = None
@@ -688,7 +688,6 @@ def mutate_file(backup, context):
 
 
 def queue_mutants(*, progress, config, mutants_queue, mutations_by_file):
-    from mutmut.cache import update_line_numbers
     from mutmut.cache import get_cached_mutation_statuses
 
     try:
@@ -938,7 +937,7 @@ class Progress(object):
 
 
 def check_coverage_data_filepaths(coverage_data):
-    for filepath in coverage_data._lines:
+    for filepath in coverage_data:
         if not os.path.exists(filepath):
             raise ValueError('Filepaths in .coverage not recognized, try recreating the .coverage file manually.')
 
@@ -1160,7 +1159,8 @@ def read_coverage_data():
         raise ImportError('The --use-coverage feature requires the coverage library. Run "pip install --force-reinstall mutmut[coverage]"') from e
     cov = Coverage('.coverage')
     cov.load()
-    return cov.get_data()
+    data = cov.get_data()
+    return {filepath: data.lines(filepath) for filepath in data.measured_files()}
 
 
 def read_patch_data(patch_file_path):
diff --git a/setup.cfg b/setup.cfg
index 91dd2f3..558f8e7 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -10,6 +10,15 @@ addopts = --junitxml=testreport.xml --strict -r fEsxXw
 [flake8]
 ignore = E501,E721
 
+[coverage:run]
+source = .
+omit =
+    .tox/*
+    venv/*
+    /private/*
+    /tmp/*
+    setup.py
+
 [coverage:report]
 exclude_lines =
     # Have to re-enable the standard pragma
diff --git a/tox.ini b/tox.ini
index 88f3095..ed1d86d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -13,9 +13,7 @@ deps =
 basepython = python3.7
 usedevelop = True
 commands =
-    {envpython} -m pytest --cov {posargs}
-    {envpython} -m coverage report -m
-    {envpython} -m coverage html
+    {envpython} -m pytest --cov --cov-config setup.cfg --cov-report term-missing --cov-report html {posargs}
 deps =
     -rrequirements.txt
     -rtest_requirements.txt


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index 80fdd9b..9b46ae7 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 
 import os
-import re
 import subprocess
 import sys
 import xml.etree.ElementTree as ET
@@ -155,7 +154,7 @@ def test_compute_return_code():
 
 
 def test_read_coverage_data(filesystem):
-    assert isinstance(read_coverage_data(), CoverageData)
+    assert read_coverage_data() == {}
 
 
 @pytest.mark.parametrize(
@@ -366,8 +365,7 @@ def test_full_run_all_suspicious_mutant_junit(filesystem):
     assert int(root.attrib['disabled']) == 0
 
 
-@pytest.mark.skip("TODO: fix support for coverage 5")
-def test_use_coverage(capsys, filesystem):
+def test_use_coverage(filesystem):
     with open(os.path.join(str(filesystem), "tests", "test_foo.py"), 'w') as f:
         f.write(test_file_contents.replace('assert foo(2, 2) is False\n', ''))
 
@@ -394,16 +392,8 @@ def test_use_coverage(capsys, filesystem):
     assert result.exit_code == 0
     assert '13/13  🎉 13  ⏰ 0  🤔 0  🙁 0' in repr(result.output)
 
-    # replace the .coverage file content with a non existent path to check if an exception is thrown
-    with open('.coverage', 'r') as f:
-        content = f.read()
-
-    # the new path is linux-based, but it just needs to be wrong
-    new_content = re.sub(r'\"[\w\W][^{]*foo.py\"', '"/test_path/foo.py"', content)
-
-    with open('.coverage', 'w') as f:
-        f.write(new_content)
-
+    # remove existent path to check if an exception is thrown
+    os.unlink(os.path.join(str(filesystem), 'foo.py'))
     with pytest.raises(ValueError,
                        match=r'^Filepaths in .coverage not recognized, try recreating the .coverage file manually.$'):
         CliRunner().invoke(climain, ['run', '--paths-to-mutate=foo.py', "--test-time-base=15.0", "--use-coverage"],