Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Raise `Cobertura.MissingFileSystem` instead of `AttributeError` when diffing
reports without source files.
* Add `--sort-by-uncovered-lines` to sort output, so the file with the most missing lines is at the
top. Thanks @guettli
* Fix: JSON and YAML output when using `--ignore-regex` in `show` command. Thanks @OidaTiftla
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,14 @@ pycobertura/utils.py 12 0 100.00%
TOTAL 253 0 100.00%"""

from pycobertura import TextReporterDelta

coverage1 = Cobertura('coverage1.xml')
coverage2 = Cobertura('coverage2.xml')
from pycobertura.filesystem import filesystem_factory

coverage1 = Cobertura(
'coverage1.xml', filesystem=filesystem_factory('source1')
)
coverage2 = Cobertura(
'coverage2.xml', filesystem=filesystem_factory('source2')
)
delta = TextReporterDelta(coverage1, coverage2)
delta.generate() == """\
Filename Stmts Miss Cover Missing
Expand Down
10 changes: 8 additions & 2 deletions pycobertura/cobertura.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ def _raise_MissingFileSystem(self, filename):
f"content of the file."
)

def _filesystem_has_file(self, filename):
if self.filesystem is None:
self._raise_MissingFileSystem(filename)

return self.filesystem.has_file(filename)

@memoize
def file_source(self, filename):
"""
Expand Down Expand Up @@ -437,7 +443,7 @@ def file_source(self, filename: str):

"""
nonexistent = True
if self.cobertura1.has_file(filename) and self.cobertura1.filesystem.has_file(
if self.cobertura1.has_file(filename) and self.cobertura1._filesystem_has_file(
filename
):
lines1 = self.cobertura1.source_lines(filename)
Expand All @@ -447,7 +453,7 @@ def file_source(self, filename: str):
lines1 = []
line_statuses1: Dict[int, LineStatus] = {}

if self.cobertura2.has_file(filename) and self.cobertura2.filesystem.has_file(
if self.cobertura2.has_file(filename) and self.cobertura2._filesystem_has_file(
filename
):
lines2 = self.cobertura2.source_lines(filename)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cobertura_diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import pytest

from .utils import make_cobertura


@pytest.mark.parametrize("filename", ["dummy/dummy.py", "dummy/dummy3.py"])
def test_diff_file_source_without_filesystem(filename):
from pycobertura.cobertura import Cobertura, CoberturaDiff

cobertura1 = Cobertura('tests/dummy.source1/coverage.xml')
cobertura2 = Cobertura('tests/dummy.source2/coverage.xml')
differ = CoberturaDiff(cobertura1, cobertura2)

with pytest.raises(Cobertura.MissingFileSystem):
differ.file_source(filename)


def test_diff_class_source():
from pycobertura.cobertura import CoberturaDiff
from pycobertura.cobertura import Line
Expand Down
Loading