diff options
author | Ned Batchelder <nedbat@gmail.com> | 2016-02-28 16:11:10 -0500 |
---|---|---|
committer | Ned Batchelder <nedbat@gmail.com> | 2016-02-28 16:11:10 -0500 |
commit | f3e7c3e8def481afb6ef4c12a1c517beb514f6aa (patch) | |
tree | e135db8b1cf3ceb99901dcb036ae35c99970da72 /coverage/parser.py | |
parent | 4afd9f8452270572a7a580775255b44178d61451 (diff) | |
parent | 8feda9baf012b2407ddfe691fd43d2d5878ad3e9 (diff) | |
download | python-coveragepy-f3e7c3e8def481afb6ef4c12a1c517beb514f6aa.tar.gz |
Merged in Nagasaki45/coverage.py (pull request #78)
State that --source value should be a comma separated list in the docs.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index f84133d..f34a26f 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() @@ -316,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}" @@ -491,6 +495,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 +677,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 +709,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 +750,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 +803,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: @@ -900,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) @@ -922,18 +932,19 @@ 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 - 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") |