Skip to content

Commit

Permalink
fix: improve an error message. #803
Browse files Browse the repository at this point in the history
Fixes #803.
  • Loading branch information
nedbat committed Feb 28, 2021
1 parent 3f38567 commit 1699725
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -37,6 +37,10 @@ Unreleased
- It has a little more room for line numbers so that 4-digit numbers work
well, fixing `issue 1124`_.

- Improved the error message when combining line and branch data, so that users
will be more likely to understand what's happening, closing `issue 803`_.

.. _issue 803: https://github.com/nedbat/coveragepy/issues/803
.. _issue 1108: https://github.com/nedbat/coveragepy/issues/1108
.. _pull request 1110: https://github.com/nedbat/coveragepy/pull/1110
.. _issue 1123: https://github.com/nedbat/coveragepy/issues/1123
Expand Down
4 changes: 2 additions & 2 deletions coverage/sqldata.py
Expand Up @@ -486,9 +486,9 @@ def _choose_lines_or_arcs(self, lines=False, arcs=False):
assert lines or arcs
assert not (lines and arcs)
if lines and self._has_arcs:
raise CoverageException("Can't add lines to existing arc data")
raise CoverageException("Can't add line measurements to existing branch data")
if arcs and self._has_lines:
raise CoverageException("Can't add arcs to existing line data")
raise CoverageException("Can't add branch measurements to existing line data")
if not self._has_arcs and not self._has_lines:
self._has_lines = lines
self._has_arcs = arcs
Expand Down
6 changes: 4 additions & 2 deletions tests/test_data.py
Expand Up @@ -159,13 +159,15 @@ def test_ok_to_add_arcs_twice(self):
def test_cant_add_arcs_with_lines(self):
covdata = CoverageData()
covdata.add_lines(LINES_1)
with pytest.raises(CoverageException, match="Can't add arcs to existing line data"):
msg = "Can't add branch measurements to existing line data"
with pytest.raises(CoverageException, match=msg):
covdata.add_arcs(ARCS_3)

def test_cant_add_lines_with_arcs(self):
covdata = CoverageData()
covdata.add_arcs(ARCS_3)
with pytest.raises(CoverageException, match="Can't add lines to existing arc data"):
msg = "Can't add line measurements to existing branch data"
with pytest.raises(CoverageException, match=msg):
covdata.add_lines(LINES_1)

def test_touch_file_with_lines(self):
Expand Down

0 comments on commit 1699725

Please sign in to comment.