diff options
author | Steve <sleonard76@gmail.com> | 2014-05-26 13:42:02 -0400 |
---|---|---|
committer | Steve <sleonard76@gmail.com> | 2014-05-26 13:42:02 -0400 |
commit | 8c2cea536675e503e2eb78fd94e04f9635129e26 (patch) | |
tree | 07bfe64e6f8ffb7fb3f5814ba3c9deec46385fd4 | |
parent | a91fb5b97886f23f78deaaaeb42daf20b898acff (diff) | |
download | python-coveragepy-8c2cea536675e503e2eb78fd94e04f9635129e26.tar.gz |
Fix formatting when no missing lines; improve tests
-rw-r--r-- | coverage/results.py | 16 | ||||
-rw-r--r-- | coverage/summary.py | 10 | ||||
-rw-r--r-- | tests/test_summary.py | 37 |
3 files changed, 57 insertions, 6 deletions
diff --git a/coverage/results.py b/coverage/results.py index ce9e0fa..94785ca 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -83,6 +83,22 @@ class Analysis(object): ) return sorted(missing) + def arcs_missing_formatted(self): + """ The missing branch arcs, formatted. + + Returns a string like "1->2, 1->3, 16->20" + + """ + arcs = self.missing_branch_arcs() + line_exits = sorted(arcs.iteritems(), key=lambda (x, _): x) + pairs = [] + for line, exits in line_exits: + exits = sorted(exits) + for exit in exits: + pair = '%d->%d' % (line, exit) + pairs.append(pair) + return ', '.join(pairs) + def arcs_unpredicted(self): """Returns a sorted list of the executed arcs missing from the code.""" possible = self.arc_possibilities() diff --git a/coverage/summary.py b/coverage/summary.py index c99c530..1e55a7d 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -37,6 +37,8 @@ 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" @@ -59,7 +61,13 @@ class SummaryReporter(Reporter): args += (nums.n_branches, nums.n_missing_branches) args += (nums.pc_covered_str,) if self.config.show_missing: - args += (analysis.missing_formatted(),) + missing_fmtd = analysis.missing_formatted() + args += (missing_fmtd,) + if self.branches: + separator = "" + if missing_fmtd: + separator = ", " + args += (separator, analysis.arcs_missing_formatted(),) outfile.write(fmt_coverage % args) total += nums except KeyboardInterrupt: # pragma: not covered diff --git a/tests/test_summary.py b/tests/test_summary.py index 61bdf37..7fd11a0 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -160,7 +160,7 @@ class SummaryTest(CoverageTest): # Name Stmts Miss Cover Missing # ----------------------------------------- - # tests/tmp 9 3 67% 3-4, 8 + # mymissing 9 3 67% 3-4, 8 self.assertEqual(self.line_count(report), 3) self.assertIn("mymissing ", report) @@ -175,21 +175,48 @@ class SummaryTest(CoverageTest): if y: print("y") return x - branch(1, 0) + branch(1, 1) """) out = self.run_command("coverage run --branch mybranch.py") - self.assertEqual(out, 'x\n') + self.assertEqual(out, 'x\ny\n') + report = self.report_from_command("coverage report --show-missing") + + # Name Stmts Miss Branch BrMiss Cover Missing + # ------------------------------------------------------- + # tests/tmp 7 0 4 2 82% Branches: 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") + + def test_report_show_missing_branches_and_lines(self): + self.make_file("mybranch.py", """\ + def branch(x, y, z): + if x: + print("x") + if y: + print("y") + if z: + if x and y: + print("z") + return x + branch(1, 1, 0) + """) + out = self.run_command("coverage run --branch mybranch.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 7 1 4 2 73% 5, Branches: 2->4, 4->5 + # tests/tmp 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 7 1 4 2 73% 5, Branches: 2->4, 4->5") + "mybranch 10 2 8 5 61% " + "7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9") def test_dotpy_not_python(self): # We run a .py file, and when reporting, we can't parse it as Python. |