summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2012-11-19 21:58:40 -0500
committerNed Batchelder <ned@nedbatchelder.com>2012-11-19 21:58:40 -0500
commitdc438780abf10e5257bb177728066e16201e3916 (patch)
tree172dc6b0d7929fb0fade8562e2e7734c985de532 /test
parentc405d15412a1e8f2d14ee0ecea9c5d4fe55641de (diff)
downloadpython-coveragepy-git-dc438780abf10e5257bb177728066e16201e3916.tar.gz
Branch coverage is computed more accurately, #156.
Diffstat (limited to 'test')
-rw-r--r--test/test_api.py3
-rw-r--r--test/test_summary.py36
2 files changed, 31 insertions, 8 deletions
diff --git a/test/test_api.py b/test/test_api.py
index e2ebc656..c15db5ed 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -511,4 +511,5 @@ class AnalysisTest(CoverageTest):
self.assertEqual(nums.n_excluded, 1)
self.assertEqual(nums.n_missing, 3)
self.assertEqual(nums.n_branches, 2)
- self.assertEqual(nums.n_missing_branches, 0)
+ self.assertEqual(nums.n_partial_branches, 0)
+ self.assertEqual(nums.n_missing_branches, 2)
diff --git a/test/test_summary.py b/test/test_summary.py
index 644aa9dd..933bcbe5 100644
--- a/test/test_summary.py
+++ b/test/test_summary.py
@@ -118,7 +118,7 @@ class SummaryTest(CoverageTest):
self.assertEqual(out, 'x\n')
report = self.report_from_command("coverage report")
- # Name Stmts Miss Branch BrPart Cover
+ # Name Stmts Miss Branch BrMiss Cover
# --------------------------------------------
# mybranch 5 0 2 1 85%
@@ -179,18 +179,40 @@ class SummaryTest(CoverageTest):
self.assertEqual(self.line_count(report), 2)
+ def get_report(self, cov):
+ """Get the report from `cov`, and canonicalize it."""
+ repout = StringIO()
+ cov.report(file=repout, show_missing=False)
+ report = repout.getvalue().replace('\\', '/')
+ report = re.sub(r" +", " ", report)
+ return report
+
+ def test_bug_156_file_not_run_should_be_zero(self):
+ # https://bitbucket.org/ned/coveragepy/issue/156
+ self.make_file("mybranch.py", """\
+ def branch(x):
+ if x:
+ print("x")
+ return x
+ branch(1)
+ """)
+ self.make_file("main.py", """\
+ print("y")
+ """)
+ cov = coverage.coverage(branch=True, source=["."])
+ cov.start()
+ import main
+ cov.stop()
+ report = self.get_report(cov).splitlines()
+ self.assertIn("mybranch 5 5 2 2 0%", report)
+
def run_TheCode_and_report_it(self):
"""A helper for the next few tests."""
cov = coverage.coverage()
cov.start()
import TheCode # pylint: disable=F0401,W0612
cov.stop()
-
- repout = StringIO()
- cov.report(file=repout, show_missing=False)
- report = repout.getvalue().replace('\\', '/')
- report = re.sub(r"\s+", " ", report)
- return report
+ return self.get_report(cov)
def test_bug_203_mixed_case_listed_twice_with_rc(self):
self.make_file("TheCode.py", "a = 1\n")