diff options
Diffstat (limited to 'coverage/results.py')
-rw-r--r-- | coverage/results.py | 71 |
1 files changed, 22 insertions, 49 deletions
diff --git a/coverage/results.py b/coverage/results.py index 0576ae1f..6cbcbfc8 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -1,11 +1,9 @@ """Results of coverage measurement.""" import collections -import os from coverage.backward import iitems -from coverage.misc import format_lines, join_regex, NoSource -from coverage.parser import CodeParser +from coverage.misc import format_lines, join_regex class Analysis(object): @@ -16,18 +14,15 @@ class Analysis(object): self.code_unit = code_unit self.filename = self.code_unit.filename - actual_filename, source = self.find_source(self.filename) - - self.parser = CodeParser( - text=source, filename=actual_filename, + self.parser = code_unit.get_parser( exclude=self.coverage._exclude_regex('exclude') ) self.statements, self.excluded = self.parser.parse_source() # Identify missing statements. executed = self.coverage.data.executed_lines(self.filename) - exec1 = self.parser.first_lines(executed) - self.missing = self.statements - exec1 + executed = self.parser.translate_lines(executed) + self.missing = self.statements - executed if self.coverage.data.has_arcs(): self.no_branch = self.parser.lines_matching( @@ -54,44 +49,6 @@ class Analysis(object): n_missing_branches=n_missing_branches, ) - def find_source(self, filename): - """Find the source for `filename`. - - Returns two values: the actual filename, and the source. - - The source returned depends on which of these cases holds: - - * The filename seems to be a non-source file: returns None - - * The filename is a source file, and actually exists: returns None. - - * The filename is a source file, and is in a zip file or egg: - returns the source. - - * The filename is a source file, but couldn't be found: raises - `NoSource`. - - """ - source = None - - base, ext = os.path.splitext(filename) - TRY_EXTS = { - '.py': ['.py', '.pyw'], - '.pyw': ['.pyw'], - } - try_exts = TRY_EXTS.get(ext) - if not try_exts: - return filename, None - - for try_ext in try_exts: - try_filename = base + try_ext - if os.path.exists(try_filename): - return try_filename, None - source = self.coverage.file_locator.get_zip_data(try_filename) - if source: - return try_filename, source - raise NoSource("No source for code: '%s'" % filename) - def missing_formatted(self): """The missing line numbers, formatted nicely. @@ -112,8 +69,7 @@ class Analysis(object): def arcs_executed(self): """Returns a sorted list of the arcs actually executed in the code.""" executed = self.coverage.data.executed_arcs(self.filename) - m2fl = self.parser.first_line - executed = ((m2fl(l1), m2fl(l2)) for (l1,l2) in executed) + executed = self.parser.translate_arcs(executed) return sorted(executed) def arcs_missing(self): @@ -127,6 +83,23 @@ class Analysis(object): ) return sorted(missing) + def arcs_missing_formatted(self): + """ The missing branch arcs, formatted nicely. + + Returns a string like "1->2, 1->3, 16->20". Omits any mention of + missing lines, so if line 17 is missing, then 16->17 won't be included. + + """ + arcs = self.missing_branch_arcs() + missing = self.missing + line_exits = sorted(iitems(arcs)) + pairs = [] + for line, exits in line_exits: + for ex in sorted(exits): + if line not in missing and ex not in missing: + pairs.append('%d->%d' % (line, ex)) + return ', '.join(pairs) + def arcs_unpredicted(self): """Returns a sorted list of the executed arcs missing from the code.""" possible = self.arc_possibilities() |