summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-07-08 06:25:17 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-07-08 06:25:17 -0400
commitc317727542e303ae9dd5ed4db73217508e367d74 (patch)
treea10fcf53481e773f1ab97eef8188b89172a68404 /tests
parenta63bf56c15835c763f60ff0ba3f782c8fb86363c (diff)
downloadpython-coveragepy-git-c317727542e303ae9dd5ed4db73217508e367d74.tar.gz
Improve branch summarization
It failed completely on more than one file! Removed the Branches label, and no longer report missing branches implied by missing lines.
Diffstat (limited to 'tests')
-rw-r--r--tests/coveragetest.py17
-rw-r--r--tests/test_summary.py35
2 files changed, 38 insertions, 14 deletions
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.