diff options
-rw-r--r-- | coverage/parser.py | 7 | ||||
-rw-r--r-- | tests/test_arcs.py | 20 | ||||
-rw-r--r-- | tests/test_parser.py | 14 |
3 files changed, 39 insertions, 2 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index 0f597744..f34a26fb 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -317,6 +317,9 @@ class PythonParser(object): if emsg is None: if end < 0: + # Hmm, maybe we have a one-line callable, let's check. + if (-end, end) in self._missing_arc_fragments: + return self.missing_arc_description(-end, end) emsg = "didn't jump to the function exit" else: emsg = "didn't jump to line {lineno}" @@ -907,7 +910,7 @@ class AstArcAnalyzer(object): if node.body: exits = self.add_body_arcs(node.body, from_start=ArcStart(-1)) for xit in exits: - self.add_arc(xit.lineno, -start, xit.cause, 'exit the module') + self.add_arc(xit.lineno, -start, xit.cause, "didn't exit the module") else: # Empty module. self.add_arc(-1, start) @@ -929,7 +932,7 @@ class AstArcAnalyzer(object): for xit in exits: self.add_arc( xit.lineno, -start, xit.cause, - "exit the body of class '{0}'".format(node.name), + "didn't exit the body of class '{0}'".format(node.name), ) def _make_oneline_code_method(noun): # pylint: disable=no-self-argument diff --git a/tests/test_arcs.py b/tests/test_arcs.py index dd7e9b37..d18faf74 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1246,6 +1246,26 @@ class LambdaArcTest(CoverageTest): arcz_unpredicted="58", ) + def test_lambda_in_dict(self): + self.check_coverage("""\ + x = 1 + x = 2 + d = { + 4: lambda: [], + 5: lambda: [], + 6: lambda: [], + 7: lambda: [], + } + + for k, v in d.items(): # 10 + if k & 1: + v() + """, + arcz=".1 12 23 3A AB BC BA CA A. .3 3-4 3-5 3-6 3-7", + arcz_missing="3-4 3-6", + arcz_unpredicted="", + ) + class AsyncTest(CoverageTest): """Tests of the new async and await keywords in Python 3.5""" diff --git a/tests/test_parser.py b/tests/test_parser.py index 0ede10b4..17f81ad8 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -329,6 +329,20 @@ class ParserMissingArcDescriptionTest(CoverageTest): "because the return on line 12 wasn't executed" ) + def test_missing_arc_descriptions_bug460(self): + parser = self.parse_text(u"""\ + x = 1 + d = { + 3: lambda: [], + 4: lambda: [], + } + x = 6 + """) + self.assertEqual( + parser.missing_arc_description(2, -3), + "line 3 didn't run the lambda on line 3", + ) + class ParserFileTest(CoverageTest): """Tests for coverage.py's code parsing from files.""" |