Skip to content

Commit

Permalink
add a fourth case to the tests for #1852
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack Weinberg committed Sep 16, 2024
1 parent c8d7397 commit 402bee8
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions tests/test_lcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def foo(a):
actual_result = self.get_lcov_report_content()
assert expected_result == actual_result

def test_genexpr_exit_arcs_pruned_when_executed(self) -> None:
def test_genexpr_exit_arcs_pruned_full_coverage(self) -> None:
self.make_file("runme.py", """\
def foo(a):
if any(x > 0 for x in a):
Expand Down Expand Up @@ -478,12 +478,13 @@ def foo(a):
actual_result = self.get_lcov_report_content()
assert expected_result == actual_result

def test_genexpr_exit_arcs_pruned_when_missing(self) -> None:
def test_genexpr_exit_arcs_pruned_never_true(self) -> None:
self.make_file("runme.py", """\
def foo(a):
if any(x > 0 for x in a):
print(f"{a!r} has positives")
foo([])
foo([0])
""")
cov = coverage.Coverage(source=".", branch=True)
self.start_import_stop(cov, "runme")
Expand All @@ -495,8 +496,9 @@ def foo(a):
DA:2,1
DA:3,0
DA:4,1
LF:4
LH:3
DA:5,1
LF:5
LH:4
"""),
textwrap.dedent("""\
FN:1,3,foo
Expand All @@ -515,7 +517,46 @@ def foo(a):
actual_result = self.get_lcov_report_content()
assert expected_result == actual_result

def test_genexpr_exit_arcs_pruned_when_not_reached(self) -> None:
def test_genexpr_exit_arcs_pruned_always_true(self) -> None:
self.make_file("runme.py", """\
def foo(a):
if any(x > 0 for x in a):
print(f"{a!r} has positives")
foo([1])
foo([1,2])
""")
cov = coverage.Coverage(source=".", branch=True)
self.start_import_stop(cov, "runme")
cov.lcov_report()
expected_result = fn_coverage_missing_in_pypy_38(
textwrap.dedent("""\
SF:runme.py
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
LF:5
LH:5
"""),
textwrap.dedent("""\
FN:1,3,foo
FNDA:1,foo
FNF:1
FNH:1
"""),
textwrap.dedent("""\
BRDA:2,0,to line 3,1
BRDA:2,0,to exit,0
BRF:2
BRH:1
end_of_record
"""),
)
actual_result = self.get_lcov_report_content()
assert expected_result == actual_result

def test_genexpr_exit_arcs_pruned_not_reached(self) -> None:
self.make_file("runme.py", """\
def foo(a):
if any(x > 0 for x in a):
Expand Down

0 comments on commit 402bee8

Please sign in to comment.