diff options
-rw-r--r-- | coverage/results.py | 10 | ||||
-rw-r--r-- | coverage/summary.py | 13 | ||||
-rw-r--r-- | tests/coveragetest.py | 17 | ||||
-rw-r--r-- | tests/test_summary.py | 35 |
4 files changed, 50 insertions, 25 deletions
diff --git a/coverage/results.py b/coverage/results.py index c9034bcd..6cbcbfc8 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -84,18 +84,20 @@ class Analysis(object): return sorted(missing) def arcs_missing_formatted(self): - """ The missing branch arcs, formatted. + """ The missing branch arcs, formatted nicely. - Returns a string like "1->2, 1->3, 16->20" + Returns a string like "1->2, 1->3, 16->20". Omits any mention of + missing lines, so if line 17 is missing, then 16->17 won't be included. """ arcs = self.missing_branch_arcs() + missing = self.missing line_exits = sorted(iitems(arcs)) pairs = [] for line, exits in line_exits: for ex in sorted(exits): - pair = '%d->%d' % (line, ex) - pairs.append(pair) + if line not in missing and ex not in missing: + pairs.append('%d->%d' % (line, ex)) return ', '.join(pairs) def arcs_unpredicted(self): diff --git a/coverage/summary.py b/coverage/summary.py index 1e55a7d4..a6768cf9 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -37,8 +37,6 @@ class SummaryReporter(Reporter): if self.config.show_missing: header += " Missing" fmt_coverage += " %s" - if self.branches: - fmt_coverage += "%sBranches: %s" rule = "-" * len(header) + "\n" header += "\n" fmt_coverage += "\n" @@ -62,12 +60,13 @@ class SummaryReporter(Reporter): args += (nums.pc_covered_str,) if self.config.show_missing: missing_fmtd = analysis.missing_formatted() - args += (missing_fmtd,) if self.branches: - separator = "" - if missing_fmtd: - separator = ", " - args += (separator, analysis.arcs_missing_formatted(),) + branches_fmtd = analysis.arcs_missing_formatted() + if branches_fmtd: + if missing_fmtd: + missing_fmtd += ", " + missing_fmtd += branches_fmtd + args += (missing_fmtd,) outfile.write(fmt_coverage % args) total += nums except KeyboardInterrupt: # pragma: not covered diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 0171ec14..1eedad39 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -489,15 +489,24 @@ class CoverageTest(TestCase): self.assertNotIn("error", report.lower()) return report + def report_lines(self, report): + """Return the lines of the report, as a list.""" + lines = report.split('\n') + self.assertEqual(lines[-1], "") + return lines[:-1] + def line_count(self, report): """How many lines are in `report`?""" - self.assertEqual(report.split('\n')[-1], "") - return len(report.split('\n')) - 1 + return len(self.report_lines(report)) + + def squeezed_lines(self, report): + """Return a list of the lines in report, with the spaces squeezed.""" + lines = self.report_lines(report) + return [re.sub(r"\s+", " ", l.strip()) for l in lines] def last_line_squeezed(self, report): """Return the last line of `report` with the spaces squeezed down.""" - last_line = report.split('\n')[-2] - return re.sub(r"\s+", " ", last_line) + return self.squeezed_lines(report)[-1] # We run some tests in temporary directories, because they may need to make # files for the tests. But this is expensive, so we can change per-class diff --git a/tests/test_summary.py b/tests/test_summary.py index 336a2af3..7bd1c496 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -174,14 +174,17 @@ class SummaryTest(CoverageTest): # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # mybranch 7 0 4 2 82% Branches: 2->4, 4->6 + # mybranch 7 0 4 2 82% 2->4, 4->6 self.assertEqual(self.line_count(report), 3) self.assertIn("mybranch ", report) self.assertEqual(self.last_line_squeezed(report), - "mybranch 7 0 4 2 82% Branches: 2->4, 4->6") + "mybranch 7 0 4 2 82% 2->4, 4->6") def test_report_show_missing_branches_and_lines(self): + self.make_file("main.py", """\ + import mybranch + """) self.make_file("mybranch.py", """\ def branch(x, y, z): if x: @@ -194,20 +197,32 @@ class SummaryTest(CoverageTest): return x branch(1, 1, 0) """) - out = self.run_command("coverage run --branch mybranch.py") + out = self.run_command("coverage run --branch main.py") self.assertEqual(out, 'x\ny\n') report = self.report_from_command("coverage report --show-missing") # pylint: disable=C0301 # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # mybranch 10 2 8 5 61% 7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9 - - self.assertEqual(self.line_count(report), 3) - self.assertIn("mybranch ", report) - self.assertEqual(self.last_line_squeezed(report), - "mybranch 10 2 8 5 61% " - "7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9") + # main 1 0 0 0 100% + # mybranch 10 2 8 5 61% 7-8, 2->4, 4->6 + # ------------------------------------------------------- + # TOTAL 11 2 8 5 63% + + self.assertEqual(self.line_count(report), 6) + squeezed = self.squeezed_lines(report) + self.assertEqual( + squeezed[2], + "main 1 0 0 0 100%" + ) + self.assertEqual( + squeezed[3], + "mybranch 10 2 8 5 61% 7-8, 2->4, 4->6" + ) + self.assertEqual( + squeezed[5], + "TOTAL 11 2 8 5 63%" + ) def test_dotpy_not_python(self): # We run a .py file, and when reporting, we can't parse it as Python. |