From 938155b8da192993485148a61fcebd066a6fe426 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 14:12:09 -0400 Subject: A bit of refactoring, inching slowly toward nicer CodeUnits --- coverage/parser.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'coverage/parser.py') 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. -- cgit v1.2.1 From a189b3bb1846d8e0c7b003a94af69822d3890f9e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 21:26:57 -0400 Subject: Continued refactoring of CodeUnit --- coverage/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'coverage/parser.py') diff --git a/coverage/parser.py b/coverage/parser.py index 88aad65f..5bb15466 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -30,7 +30,7 @@ class CodeParser(object): class PythonParser(CodeParser): """Parse code to find executable lines, excluded lines, etc.""" - def __init__(self, cu, text=None, filename=None, exclude=None): + def __init__(self, text=None, filename=None, exclude=None): """ Source can be provided as `text`, the text itself, or `filename`, from which the text will be read. Excluded lines are those that match -- cgit v1.2.1 From 44527cc9db62aa3979c69abe4edb7070aafd6897 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 12 Jun 2014 17:17:38 -0400 Subject: Hacked-in django template support --HG-- branch : django --- coverage/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'coverage/parser.py') diff --git a/coverage/parser.py b/coverage/parser.py index 5bb15466..c5e95baa 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -15,7 +15,7 @@ class CodeParser(object): Base class for any code parser. """ def translate_lines(self, lines): - return lines + return set(lines) def translate_arcs(self, arcs): return arcs -- cgit v1.2.1