Skip to content

Commit

Permalink
- added "brCov%" column to text output, with just the branch coverage
Browse files Browse the repository at this point in the history
  percentage, as in some cases (such as papers on test generation) that
  is more relevant than a combined metric;
  • Loading branch information
jaltmayerpizzorno committed Nov 27, 2023
1 parent 0a20448 commit 973bebf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/slipcover/slipcover.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,15 @@ def table():
if self.branch:
exec_b = len(f_info['executed_branches'])
miss_b = len(f_info['missing_branches'])
pct_b = 100*exec_b/(exec_b+miss_b) if (exec_b+miss_b) else 0

pct = f_info['summary']['percent_covered']

if self.skip_covered and pct == 100.0:
continue

yield [f, exec_l+miss_l, miss_l,
*([exec_b+miss_b, miss_b] if self.branch else []),
*([exec_b+miss_b, miss_b, round(pct_b)] if self.branch else []),
round(pct),
Slipcover.format_missing(f_info['missing_lines'], f_info['executed_lines'],
f_info['missing_branches'] if 'missing_branches' in f_info else [])]
Expand All @@ -489,14 +490,20 @@ def table():
yield ['---'] + [''] * (6 if self.branch else 4)

s = cov['summary']

if self.branch:
exec_b = s['covered_branches']
miss_b = s['missing_branches']
pct_b = 100*exec_b/(exec_b+miss_b) if (exec_b+miss_b) else 0

yield ['(summary)', s['covered_lines']+s['missing_lines'], s['missing_lines'],
*([s['covered_branches']+s['missing_branches'], s['missing_branches']] if self.branch else []),
*([exec_b+miss_b, miss_b, round(pct_b)] if self.branch else []),
round(s['percent_covered']), '']



print("", file=outfile)
headers = ["File", "#lines", "#l.miss", *(["#br.", "#br.miss"] if self.branch else []), "Cover%", "Missing"]
headers = ["File", "#lines", "#l.miss", *(["#br.", "#br.miss", "brCov%", "totCov%"] if self.branch else ["Cover%"]), "Missing"]
maxcolwidths = [None] * (len(headers)-1) + [missing_width]
print(tabulate(table(), headers=headers, maxcolwidths=maxcolwidths), file=outfile)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,13 @@ def foo(x):
total_b = exec_b + miss_b

pct = round(100*(exec_l+exec_b)/(total_l+total_b))
pct_b = round(100*exec_b/total_b)

# TODO test more cases (multiple files, etc.)
output = capsys.readouterr()[0]
print(output)
output = output.splitlines()
assert re.match(f'^foo\\.py +{total_l} +{miss_l} +{total_b} +{miss_b} +{pct}', output[3])
assert re.match(f'^foo\\.py +{total_l} +{miss_l} +{total_b} +{miss_b} +{pct_b} +{pct}', output[3])


@pytest.mark.parametrize("do_branch", [True, False])
Expand All @@ -411,7 +412,7 @@ def test_print_coverage_zero_lines(do_branch, capsys):
sci.print_coverage(sys.stdout)
output = capsys.readouterr()[0]
output = output.splitlines()
assert re.match(f'^foo\\.py +{"1" if PYTHON_VERSION < (3,11) else "0"} +0{" +0 +0" if do_branch else ""} +100', output[3])
assert re.match(f'^foo\\.py +{"1" if PYTHON_VERSION < (3,11) else "0"} +0{" +0 +0 +0" if do_branch else ""} +100', output[3])


def test_print_coverage_skip_covered():
Expand Down

0 comments on commit 973bebf

Please sign in to comment.