diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-09 12:20:02 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-09 12:20:02 -0400 |
commit | bee953400bae23f82ae021035aae0d784f6217d2 (patch) | |
tree | 2b7ea710d6294a2136b5e9e2c90d88903abd62fe | |
parent | db93205a36d4e55ae01c0c625c446b74e0438797 (diff) | |
download | python-coveragepy-git-bee953400bae23f82ae021035aae0d784f6217d2.tar.gz |
Rename .statements and .excluded_statements to .lines and .excluded_lines
-rw-r--r-- | coverage/plugin.py | 66 | ||||
-rw-r--r-- | coverage/plugin_support.py | 12 | ||||
-rw-r--r-- | coverage/python.py | 4 | ||||
-rw-r--r-- | coverage/results.py | 4 | ||||
-rw-r--r-- | coverage/xmlreport.py | 2 | ||||
-rw-r--r-- | tests/plugin1.py | 5 | ||||
-rw-r--r-- | tests/plugin2.py | 2 |
7 files changed, 55 insertions, 40 deletions
diff --git a/coverage/plugin.py b/coverage/plugin.py index c569d26d..48395299 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -151,41 +151,35 @@ class FileTracer(object): class FileReporter(object): """Support needed for files during the reporting phase.""" + def __init__(self, filename): - # TODO: document that this init happens. + """Simple initialization of a `FileReporter`. + + The `filename` argument is the path to the file being reported. This + will be available as the `.filename` attribute on the object. Other + method implementations on this base class rely on this attribute. + + """ self.filename = filename def __repr__(self): return "<{0.__class__.__name__} filename={0.filename!r}>".format(self) def relative_filename(self): - return files.relative_filename(self.filename) + """Return the relative filename for this file. - # Annoying comparison operators. Py3k wants __lt__ etc, and Py2k needs all - # of them defined. - - def __eq__(self, other): - return isinstance(other, FileReporter) and self.filename == other.filename - - def __ne__(self, other): - return not (self == other) + This file path will be displayed in reports. You only need to supply + this method if you have an unusual syntax for file paths. The default + implementation will supply the actual project-relative file path. - def __lt__(self, other): - return self.filename < other.filename - - def __le__(self, other): - return self.filename <= other.filename - - def __gt__(self, other): - return self.filename > other.filename - - def __ge__(self, other): - return self.filename >= other.filename + """ + return files.relative_filename(self.filename) - def statements(self): + def lines(self): + """Return a set of executable lines""" _needs_to_implement(self, "statements") - def excluded_statements(self): + def excluded_lines(self): return set([]) def translate_lines(self, lines): @@ -210,7 +204,31 @@ class FileReporter(object): return f.read() def source_token_lines(self): - """Return the 'tokenized' text for the code.""" + """Return the 'tokenized' text for the code. + + 'str', 'nam', 'num', 'key', 'com', 'op' + """ # A generic implementation, each line is one "txt" token. for line in self.source().splitlines(): yield [('txt', line)] + + # Annoying comparison operators. Py3k wants __lt__ etc, and Py2k needs all + # of them defined. + + def __eq__(self, other): + return isinstance(other, FileReporter) and self.filename == other.filename + + def __ne__(self, other): + return not (self == other) + + def __lt__(self, other): + return self.filename < other.filename + + def __le__(self, other): + return self.filename <= other.filename + + def __gt__(self, other): + return self.filename > other.filename + + def __ge__(self, other): + return self.filename >= other.filename diff --git a/coverage/plugin_support.py b/coverage/plugin_support.py index 92246d46..8863b435 100644 --- a/coverage/plugin_support.py +++ b/coverage/plugin_support.py @@ -198,14 +198,14 @@ class DebugFileReporterWrapper(FileReporter): self.debug.write("relative_filename() --> %r" % (ret,)) return ret - def statements(self): - ret = self.reporter.statements() - self.debug.write("statements() --> %r" % (ret,)) + def lines(self): + ret = self.reporter.lines() + self.debug.write("lines() --> %r" % (ret,)) return ret - def excluded_statements(self): - ret = self.reporter.excluded_statements() - self.debug.write("excluded_statements() --> %r" % (ret,)) + def excluded_lines(self): + ret = self.reporter.excluded_lines() + self.debug.write("excluded_lines() --> %r" % (ret,)) return ret def translate_lines(self, lines): diff --git a/coverage/python.py b/coverage/python.py index 94d20fd8..e6e9493a 100644 --- a/coverage/python.py +++ b/coverage/python.py @@ -126,13 +126,13 @@ class PythonFileReporter(FileReporter): ) return self._parser - def statements(self): + def lines(self): """Return the line numbers of statements in the file.""" if self._statements is None: self._statements, self._excluded = self.parser.parse_source() return self._statements - def excluded_statements(self): + def excluded_lines(self): """Return the line numbers of statements in the file.""" if self._excluded is None: self._statements, self._excluded = self.parser.parse_source() diff --git a/coverage/results.py b/coverage/results.py index 2e82e24d..b2848d02 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -16,8 +16,8 @@ class Analysis(object): self.data = data self.file_reporter = file_reporter self.filename = self.file_reporter.filename - self.statements = self.file_reporter.statements() - self.excluded = self.file_reporter.excluded_statements() + self.statements = self.file_reporter.lines() + self.excluded = self.file_reporter.excluded_lines() # Identify missing statements. executed = self.data.lines(self.filename) or [] diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 1f452c5c..d547559c 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -127,7 +127,7 @@ class XmlReporter(Reporter): # Create the 'lines' and 'package' XML elements, which # are populated later. Note that a package == a directory. - filename = files.relative_filename(fr.filename) + filename = fr.relative_filename() filename = filename.replace("\\", "/") dirname = os.path.dirname(filename) or "." parts = dirname.split("/") diff --git a/tests/plugin1.py b/tests/plugin1.py index 5340e40d..af4dfc52 100644 --- a/tests/plugin1.py +++ b/tests/plugin1.py @@ -42,12 +42,9 @@ class FileTracer(coverage.FileTracer): class FileReporter(coverage.FileReporter): """Dead-simple FileReporter.""" - def statements(self): + def lines(self): return set([105, 106, 107, 205, 206, 207]) - def excluded_statements(self): - return set([]) - def coverage_init(reg, options): # pylint: disable=unused-argument """Called by coverage to initialize the plugins here.""" diff --git a/tests/plugin2.py b/tests/plugin2.py index 226d4e55..3bdfbdfd 100644 --- a/tests/plugin2.py +++ b/tests/plugin2.py @@ -37,7 +37,7 @@ class RenderFileTracer(coverage.FileTracer): class FileReporter(coverage.FileReporter): """A goofy file reporter.""" - def statements(self): + def lines(self): # Goofy test arrangement: claim that the file has as many lines as the # number in its name. num = os.path.basename(self.filename).split(".")[0].split("_")[1] |