diff --git a/src/slipcover/slipcover.py b/src/slipcover/slipcover.py index 0fde04d..fb207f5 100644 --- a/src/slipcover/slipcover.py +++ b/src/slipcover/slipcover.py @@ -473,6 +473,7 @@ 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'] @@ -480,7 +481,7 @@ def table(): 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 [])] @@ -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) diff --git a/tests/test_coverage.py b/tests/test_coverage.py index aa3a627..907147a 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -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]) @@ -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():