diff options
-rw-r--r-- | CHANGES.rst | 5 | ||||
-rw-r--r-- | coverage/data.py | 10 | ||||
-rw-r--r-- | tests/test_arcs.py | 16 | ||||
-rw-r--r-- | tests/test_data.py | 2 |
4 files changed, 28 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 6d3afb60..8fba35bb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,10 @@ Unreleased some other line when an exception other than ``X`` happens. This jump is no longer considered a branch when measuring branch coverage. +- When measuring branch coverage, ``yield`` statements that were never resumed + were incorrectly marked as missing, as reported in `issue 440`_. This is now + fixed. + - The HTML report now has a map of the file along the rightmost edge of the page, giving an overview of where the missed lines are. Thanks, Dmitry Shishov. @@ -20,6 +24,7 @@ Unreleased - The HTML report now uses different monospaced fonts, favoring Consolas over Courier. +.. _issue 440: https://bitbucket.org/ned/coveragepy/issues/440/yielded-twisted-failure-marked-as-missed Version 4.1b2 --- 2016-01-23 ---------------------------- diff --git a/coverage/data.py b/coverage/data.py index 17cf73ce..60e104d9 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -4,6 +4,7 @@ """Coverage data for coverage.py.""" import glob +import itertools import json import optparse import os @@ -178,11 +179,12 @@ class CoverageData(object): """ if self._arcs is not None: - if filename in self._arcs: - return [s for s, __ in self._arcs[filename] if s > 0] + arcs = self._arcs.get(filename) + if arcs is not None: + all_lines = itertools.chain.from_iterable(arcs) + return list(set(l for l in all_lines if l > 0)) elif self._lines is not None: - if filename in self._lines: - return self._lines[filename] + return self._lines.get(filename) return None def arcs(self, filename): diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 030b719d..60cef938 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -981,6 +981,22 @@ class YieldTest(CoverageTest): arcz_unpredicted="5.", ) + def test_abandoned_yield(self): + # https://bitbucket.org/ned/coveragepy/issue/440 + self.check_coverage("""\ + def gen(): + print("yup") + yield "yielded" + print("nope") + + print(next(gen())) + """, + lines=[1, 2, 3, 4, 6], + missing="4", + arcz=".1 16 6. .2 23 34 4.", + arcz_missing="34 4.", + ) + class MiscArcTest(CoverageTest): """Miscellaneous arc-measuring tests.""" diff --git a/tests/test_data.py b/tests/test_data.py index b3882726..52702e97 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -66,7 +66,7 @@ ARCS_4 = { (1000, -1): None, }, } -SUMMARY_3_4 = {'x.py': 5, 'y.py': 2, 'z.py': 1} +SUMMARY_3_4 = {'x.py': 4, 'y.py': 2, 'z.py': 1} MEASURED_FILES_3_4 = ['x.py', 'y.py', 'z.py'] |