diff options
-rw-r--r-- | coverage/html.py | 3 | ||||
-rw-r--r-- | coverage/parser.py | 22 | ||||
-rw-r--r-- | coverage/plugin.py | 14 | ||||
-rw-r--r-- | tests/test_html.py | 14 | ||||
-rw-r--r-- | tests/test_parser.py | 3 |
5 files changed, 33 insertions, 23 deletions
diff --git a/coverage/html.py b/coverage/html.py index 0d6e6f96..7567c605 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -231,7 +231,8 @@ class HtmlReporter(Reporter): else: annotate_long = "%d missed branches: %s" % ( len(longs), - ", ".join("%d) %s" % (num, ann_long) for num, ann_long in enumerate(longs, start=1)), + ", ".join("%d) %s" % (num, ann_long) + for num, ann_long in enumerate(longs, start=1)), ) elif lineno in analysis.statements: line_class.append(c_run) diff --git a/coverage/parser.py b/coverage/parser.py index f84133d2..0f597744 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -305,6 +305,7 @@ class PythonParser(object): return exit_counts def missing_arc_description(self, start, end): + """Provide an English sentence describing a missing arc.""" if self._missing_arc_fragments is None: self._analyze_ast() @@ -491,6 +492,7 @@ class AstArcAnalyzer(object): code_object_handler(node) def add_arc(self, start, end, smsg=None, emsg=None): + """Add an arc, including message fragments to use if it is missing.""" if self.debug: print("\nAdding arc: ({}, {}): {!r}, {!r}".format(start, end, smsg, emsg)) print(short_stack(limit=6)) @@ -672,7 +674,8 @@ class AstArcAnalyzer(object): @contract(returns='ArcStarts') def _handle__Break(self, node): here = self.line_for_node(node) - self.process_break_exits([ArcStart(here, cause="the break on line {lineno} wasn't executed")]) + break_start = ArcStart(here, cause="the break on line {lineno} wasn't executed") + self.process_break_exits([break_start]) return set() @contract(returns='ArcStarts') @@ -703,7 +706,8 @@ class AstArcAnalyzer(object): @contract(returns='ArcStarts') def _handle__Continue(self, node): here = self.line_for_node(node) - self.process_continue_exits([ArcStart(here, cause="the continue on line {lineno} wasn't executed")]) + continue_start = ArcStart(here, cause="the continue on line {lineno} wasn't executed") + self.process_continue_exits([continue_start]) return set() @contract(returns='ArcStarts') @@ -743,14 +747,16 @@ class AstArcAnalyzer(object): @contract(returns='ArcStarts') def _handle__Raise(self, node): here = self.line_for_node(node) - self.process_raise_exits([ArcStart(here, cause="the raise on line {lineno} wasn't executed")]) + raise_start = ArcStart(here, cause="the raise on line {lineno} wasn't executed") + self.process_raise_exits([raise_start]) # `raise` statement jumps away, no exits from here. return set() @contract(returns='ArcStarts') def _handle__Return(self, node): here = self.line_for_node(node) - self.process_return_exits([ArcStart(here, cause="the return on line {lineno} wasn't executed")]) + return_start = ArcStart(here, cause="the return on line {lineno} wasn't executed") + self.process_return_exits([return_start]) # `return` statement jumps away, no exits from here. return set() @@ -794,7 +800,8 @@ class AstArcAnalyzer(object): if last_handler_start is not None: self.add_arc(last_handler_start, handler_start) last_handler_start = handler_start - from_start = ArcStart(handler_start, cause="the exception caught by line {lineno} didn't happen") + from_cause = "the exception caught by line {lineno} didn't happen" + from_start = ArcStart(handler_start, cause=from_cause) handler_exits |= self.add_body_arcs(handler_node.body, from_start=from_start) if node.orelse: @@ -926,14 +933,15 @@ class AstArcAnalyzer(object): ) def _make_oneline_code_method(noun): # pylint: disable=no-self-argument - def _method(self, node): + """A function to make methods for online callable _code_object__ methods.""" + def _code_object__oneline_callable(self, node): start = self.line_for_node(node) self.add_arc(-1, start) self.add_arc( start, -start, None, "didn't run the {0} on line {1}".format(noun, start), ) - return _method + return _code_object__oneline_callable _code_object__Lambda = _make_oneline_code_method("lambda") _code_object__GeneratorExp = _make_oneline_code_method("generator expression") diff --git a/coverage/plugin.py b/coverage/plugin.py index 85521e34..97d9c16e 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -330,19 +330,13 @@ class FileReporter(object): return {} def missing_arc_description(self, start, end): - """Provide an English phrase describing a missing arc. + """Provide an English sentence describing a missing arc. - For an arc like (123, 456), it should read well to use the phrase like - this:: - - "Line {0} didn't {1}".format(123, missing_arc_description(123, 456)) - - TODO: say more. - - By default, this simply returns the string "jump to {end}". + By default, this simply returns the string "Line {start} didn't jump + to {end}". """ - return "jump to line {end}".format(end=end) + return "Line {start} didn't jump to line {end}".format(start=start, end=end) def source_token_lines(self): """Generate a series of tokenized lines, one for each line in `source`. diff --git a/tests/test_html.py b/tests/test_html.py index 67c6d9b6..e67e4f5b 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -525,12 +525,18 @@ class HtmlGoldTests(CoverageGoldTest): '<span class="num">3</span>'), '<span class="pc_cov">70%</span>', ('<span class="annotate short">8 ↛ 11</span>' - '<span class="annotate long">line 8 didn\'t jump to line 11, because the condition on line 8 was never false</span>'), + '<span class="annotate long">line 8 didn\'t jump to line 11, ' + 'because the condition on line 8 was never false</span>'), ('<span class="annotate short">17 ↛ exit</span>' - '<span class="annotate long">line 17 didn\'t return from function \'two\', because the condition on line 17 was never false</span>'), + '<span class="annotate long">line 17 didn\'t return from function \'two\', ' + 'because the condition on line 17 was never false</span>'), ('<span class="annotate short">25 ↛ 26, ' - '25 ↛ 28</span>' - '<span class="annotate long">2 missed branches: 1) line 25 didn\'t jump to line 26, because the condition on line 25 was never true, 2) line 25 didn\'t jump to line 28, because the condition on line 25 was never false</span>'), + '25 ↛ 28</span>' + '<span class="annotate long">2 missed branches: ' + '1) line 25 didn\'t jump to line 26, ' + 'because the condition on line 25 was never true, ' + '2) line 25 didn\'t jump to line 28, ' + 'because the condition on line 25 was never false</span>'), ) contains( "out/b_branch/index.html", diff --git a/tests/test_parser.py b/tests/test_parser.py index 1be5e16c..0ede10b4 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -224,7 +224,8 @@ class ParserMissingArcDescriptionTest(CoverageTest): ) self.assertEqual( parser.missing_arc_description(6, -5), - "line 6 didn't return from function 'func5', because the loop on line 6 didn't complete" + "line 6 didn't return from function 'func5', " + "because the loop on line 6 didn't complete" ) self.assertEqual( parser.missing_arc_description(6, 7), |