summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-05-18 14:12:09 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-05-18 14:12:09 -0400
commit938155b8da192993485148a61fcebd066a6fe426 (patch)
tree7f485871b3c5ad8b282b52390028d581d1a2992a /coverage
parent3e6424948dc4185bf22bb6dcfd2c326cb88d1e97 (diff)
downloadpython-coveragepy-git-938155b8da192993485148a61fcebd066a6fe426.tar.gz
A bit of refactoring, inching slowly toward nicer CodeUnits
Diffstat (limited to 'coverage')
-rw-r--r--coverage/parser.py36
-rw-r--r--coverage/results.py4
2 files changed, 22 insertions, 18 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index cfaf02fa..88aad65f 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -14,24 +14,12 @@ class CodeParser(object):
"""
Base class for any code parser.
"""
- def _adjust_filename(self, fname):
- return fname
-
- def first_lines(self, lines):
- """Map the line numbers in `lines` to the correct first line of the
- statement.
-
- Returns a set of the first lines.
-
- """
- return set(self.first_line(l) for l in lines)
-
- def first_line(self, line):
- return line
-
def translate_lines(self, lines):
return lines
+ def translate_arcs(self, arcs):
+ return arcs
+
def exit_counts(self):
return {}
@@ -197,6 +185,24 @@ class PythonParser(CodeParser):
else:
return line
+ def first_lines(self, lines):
+ """Map the line numbers in `lines` to the correct first line of the
+ statement.
+
+ Returns a set of the first lines.
+
+ """
+ return set(self.first_line(l) for l in lines)
+
+ def translate_lines(self, lines):
+ return self.first_lines(lines)
+
+ def translate_arcs(self, arcs):
+ return [
+ (self.first_line(a), self.first_line(b))
+ for (a, b) in arcs
+ ]
+
def parse_source(self):
"""Parse source text to find executable lines, excluded lines, etc.
diff --git a/coverage/results.py b/coverage/results.py
index 08329766..e422730d 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -26,7 +26,6 @@ class Analysis(object):
# Identify missing statements.
executed = self.coverage.data.executed_lines(self.filename)
executed = self.parser.translate_lines(executed)
- executed = self.parser.first_lines(executed)
self.missing = self.statements - executed
if self.coverage.data.has_arcs():
@@ -74,8 +73,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):