From 01cf50c7d9131af2de9aea1e3573bdff1dc48110 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 24 Nov 2024 17:05:49 -0500 Subject: [PATCH] test: add a test to satisfy a condition in results.py --- coverage/results.py | 3 +-- tests/test_json.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/coverage/results.py b/coverage/results.py index dd14c8a27..39612a8a7 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -202,8 +202,7 @@ def missing_branch_arcs(self) -> dict[TLineNo, list[TLineNo]]: branch_lines = set(self._branch_lines()) mba = collections.defaultdict(list) for l1, l2 in missing: - if l1 == l2: - continue + assert l1 != l2, f"In {self.filename}, didn't expect {l1} == {l2}" if l1 in branch_lines: mba[l1].append(l2) return mba diff --git a/tests/test_json.py b/tests/test_json.py index 0ccfd84c0..e5b116ac4 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -559,3 +559,20 @@ def test_context_non_relative(self) -> None: def test_context_relative(self) -> None: self.run_context_test(relative_files=True) + + def test_l1_equals_l2(self) -> None: + # In results.py, we had a line checking `if l1 == l2` that was never + # true. This test makes it true. The annotations are essential, I + # don't know why. + self.make_file("wtf.py", """\ + def function( + x: int, + y: int, + ) -> None: + return x + y + + assert function(3, 5) == 8 + """) + cov = coverage.Coverage(branch=True) + mod = self.start_import_stop(cov, "wtf") + cov.json_report(mod)