summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-02-22 08:10:32 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-02-22 08:10:32 -0500
commit995debcded55817348cc640cac8ea07ca12bd57c (patch)
tree8adc20ab1e5acf92abcb1cb62d16ffc011b0cb22
parent73cb722150e74d123df152ff1b40e55972ccbafb (diff)
downloadpython-coveragepy-git-995debcded55817348cc640cac8ea07ca12bd57c.tar.gz
Remove every last trace of CodeUnit, and bring me a glass of vodka
-rw-r--r--coverage/annotate.py10
-rw-r--r--coverage/html.py18
-rw-r--r--coverage/htmlfiles/pyfile.html4
-rw-r--r--coverage/report.py44
-rw-r--r--coverage/results.py6
-rw-r--r--coverage/summary.py14
-rw-r--r--coverage/xmlreport.py6
-rw-r--r--lab/dataflow.txt2
-rw-r--r--tests/test_filereporter.py2
9 files changed, 53 insertions, 53 deletions
diff --git a/coverage/annotate.py b/coverage/annotate.py
index 3487feb6..b77df4ec 100644
--- a/coverage/annotate.py
+++ b/coverage/annotate.py
@@ -41,10 +41,10 @@ class AnnotateReporter(Reporter):
"""
self.report_files(self.annotate_file, morfs, directory)
- def annotate_file(self, cu, analysis):
+ def annotate_file(self, fr, analysis):
"""Annotate a single file.
- `cu` is the CodeUnit for the file to annotate.
+ `fr` is the FileReporter for the file to annotate.
"""
statements = sorted(analysis.statements)
@@ -52,18 +52,18 @@ class AnnotateReporter(Reporter):
excluded = sorted(analysis.excluded)
if self.directory:
- dest_file = os.path.join(self.directory, cu.flat_rootname())
+ dest_file = os.path.join(self.directory, fr.flat_rootname())
if dest_file.endswith("_py"):
dest_file = dest_file[:-3] + ".py"
dest_file += ",cover"
else:
- dest_file = cu.filename + ",cover"
+ dest_file = fr.filename + ",cover"
with open(dest_file, 'w') as dest:
i = 0
j = 0
covered = True
- source = cu.source()
+ source = fr.source()
for lineno, line in enumerate(source.splitlines(True), start=1):
while i < len(statements) and statements[i] < lineno:
i += 1
diff --git a/coverage/html.py b/coverage/html.py
index 2a9e0d11..96282161 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -150,20 +150,20 @@ class HtmlReporter(Reporter):
with open(fname, "wb") as fout:
fout.write(html.encode('ascii', 'xmlcharrefreplace'))
- def file_hash(self, source, cu):
+ def file_hash(self, source, fr):
"""Compute a hash that changes if the file needs to be re-reported."""
m = Hasher()
m.update(source)
- self.coverage.data.add_to_hash(cu.filename, m)
+ self.coverage.data.add_to_hash(fr.filename, m)
return m.hexdigest()
- def html_file(self, cu, analysis):
+ def html_file(self, fr, analysis):
"""Generate an HTML file for one source file."""
- source = cu.source()
+ source = fr.source()
# Find out if the file on disk is already correct.
- flat_rootname = cu.flat_rootname()
- this_hash = self.file_hash(source.encode('utf-8'), cu)
+ flat_rootname = fr.flat_rootname()
+ this_hash = self.file_hash(source.encode('utf-8'), fr)
that_hash = self.status.file_hash(flat_rootname)
if this_hash == that_hash:
# Nothing has changed to require the file to be reported again.
@@ -186,7 +186,7 @@ class HtmlReporter(Reporter):
lines = []
- for lineno, line in enumerate(cu.source_token_lines(), start=1):
+ for lineno, line in enumerate(fr.source_token_lines(), start=1):
# Figure out how to mark this line.
line_class = []
annotate_html = ""
@@ -236,7 +236,7 @@ class HtmlReporter(Reporter):
template_values = {
'c_exc': c_exc, 'c_mis': c_mis, 'c_par': c_par, 'c_run': c_run,
'arcs': self.arcs, 'extra_css': self.extra_css,
- 'cu': cu, 'nums': nums, 'lines': lines,
+ 'fr': fr, 'nums': nums, 'lines': lines,
}
html = spaceless(self.source_tmpl.render(template_values))
@@ -248,7 +248,7 @@ class HtmlReporter(Reporter):
index_info = {
'nums': nums,
'html_filename': html_filename,
- 'name': cu.name,
+ 'name': fr.name,
}
self.files.append(index_info)
self.status.set_index_info(flat_rootname, index_info)
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index 38dfb47b..f9d898aa 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -5,7 +5,7 @@
{# IE8 rounds line-height incorrectly, and adding this emulateIE7 line makes it right! #}
{# http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/7684445e-f080-4d8f-8529-132763348e21 #}
<meta http-equiv='X-UA-Compatible' content='IE=emulateIE7' />
- <title>Coverage for {{cu.name|escape}}: {{nums.pc_covered_str}}%</title>
+ <title>Coverage for {{fr.name|escape}}: {{nums.pc_covered_str}}%</title>
<link rel='stylesheet' href='style.css' type='text/css'>
{% if extra_css %}
<link rel='stylesheet' href='{{ extra_css }}' type='text/css'>
@@ -22,7 +22,7 @@
<div id='header'>
<div class='content'>
- <h1>Coverage for <b>{{cu.name|escape}}</b> :
+ <h1>Coverage for <b>{{fr.name|escape}}</b> :
<span class='pc_cov'>{{nums.pc_covered_str}}%</span>
</h1>
diff --git a/coverage/report.py b/coverage/report.py
index 93b6c928..33a46070 100644
--- a/coverage/report.py
+++ b/coverage/report.py
@@ -19,40 +19,40 @@ class Reporter(object):
self.coverage = coverage
self.config = config
- # The code units to report on. Set by find_code_units.
- self.code_units = []
+ # The FileReporters to report on. Set by find_file_reporters.
+ self.file_reporters = []
# The directory into which to place the report, used by some derived
# classes.
self.directory = None
- def find_code_units(self, morfs):
- """Find the code units we'll report on.
+ def find_file_reporters(self, morfs):
+ """Find the FileReporters we'll report on.
`morfs` is a list of modules or filenames.
"""
- self.code_units = self.coverage._get_file_reporters(morfs)
+ self.file_reporters = self.coverage._get_file_reporters(morfs)
if self.config.include:
patterns = prep_patterns(self.config.include)
matcher = FnmatchMatcher(patterns)
filtered = []
- for cu in self.code_units:
- if matcher.match(cu.filename):
- filtered.append(cu)
- self.code_units = filtered
+ for fr in self.file_reporters:
+ if matcher.match(fr.filename):
+ filtered.append(fr)
+ self.file_reporters = filtered
if self.config.omit:
patterns = prep_patterns(self.config.omit)
matcher = FnmatchMatcher(patterns)
filtered = []
- for cu in self.code_units:
- if not matcher.match(cu.filename):
- filtered.append(cu)
- self.code_units = filtered
+ for fr in self.file_reporters:
+ if not matcher.match(fr.filename):
+ filtered.append(fr)
+ self.file_reporters = filtered
- self.code_units.sort()
+ self.file_reporters.sort()
def report_files(self, report_fn, morfs, directory=None):
"""Run a reporting function on a number of morfs.
@@ -60,29 +60,29 @@ class Reporter(object):
`report_fn` is called for each relative morf in `morfs`. It is called
as::
- report_fn(code_unit, analysis)
+ report_fn(file_reporter, analysis)
- where `code_unit` is the `CodeUnit` for the morf, and `analysis` is
- the `Analysis` for the morf.
+ where `file_reporter` is the `FileReporter` for the morf, and
+ `analysis` is the `Analysis` for the morf.
"""
- self.find_code_units(morfs)
+ self.find_file_reporters(morfs)
- if not self.code_units:
+ if not self.file_reporters:
raise CoverageException("No data to report.")
self.directory = directory
if self.directory and not os.path.exists(self.directory):
os.makedirs(self.directory)
- for cu in self.code_units:
+ for fr in self.file_reporters:
try:
- report_fn(cu, self.coverage._analyze(cu))
+ report_fn(fr, self.coverage._analyze(fr))
except NoSource:
if not self.config.ignore_errors:
raise
except NotPython:
# Only report errors for .py files, and only if we didn't
# explicitly suppress those errors.
- if cu.should_be_python() and not self.config.ignore_errors:
+ if fr.should_be_python() and not self.config.ignore_errors:
raise
diff --git a/coverage/results.py b/coverage/results.py
index 0b27971f..c1718d46 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -7,11 +7,11 @@ from coverage.misc import format_lines
class Analysis(object):
- """The results of analyzing a code unit."""
+ """The results of analyzing a FileReporter."""
- def __init__(self, cov, code_unit):
+ def __init__(self, cov, file_reporters):
self.coverage = cov
- self.file_reporter = code_unit
+ self.file_reporter = file_reporters
self.filename = self.file_reporter.filename
self.statements = self.file_reporter.statements()
self.excluded = self.file_reporter.excluded_statements()
diff --git a/coverage/summary.py b/coverage/summary.py
index 10ac7e2c..5b8c903f 100644
--- a/coverage/summary.py
+++ b/coverage/summary.py
@@ -20,10 +20,10 @@ class SummaryReporter(Reporter):
`outfile` is a file object to write the summary to.
"""
- self.find_code_units(morfs)
+ self.find_file_reporters(morfs)
# Prepare the formatting strings
- max_name = max([len(cu.name) for cu in self.code_units] + [5])
+ max_name = max([len(fr.name) for fr in self.file_reporters] + [5])
fmt_name = "%%- %ds " % max_name
fmt_err = "%s %s: %s\n"
header = (fmt_name % "Name") + " Stmts Miss"
@@ -50,9 +50,9 @@ class SummaryReporter(Reporter):
total = Numbers()
- for cu in self.code_units:
+ for fr in self.file_reporters:
try:
- analysis = self.coverage._analyze(cu)
+ analysis = self.coverage._analyze(fr)
nums = analysis.numbers
if self.config.skip_covered:
@@ -65,7 +65,7 @@ class SummaryReporter(Reporter):
if no_missing_lines and no_missing_branches:
continue
- args = (cu.name, nums.n_statements, nums.n_missing)
+ args = (fr.name, nums.n_statements, nums.n_missing)
if self.branches:
args += (nums.n_branches, nums.n_partial_branches)
args += (nums.pc_covered_str,)
@@ -84,10 +84,10 @@ class SummaryReporter(Reporter):
report_it = not self.config.ignore_errors
if report_it:
typ, msg = sys.exc_info()[:2]
- if typ is NotPython and not cu.should_be_python():
+ if typ is NotPython and not fr.should_be_python():
report_it = False
if report_it:
- outfile.write(fmt_err % (cu.name, typ.__name__, msg))
+ outfile.write(fmt_err % (fr.name, typ.__name__, msg))
if total.n_files > 1:
outfile.write(rule)
diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py
index df489935..996f19a2 100644
--- a/coverage/xmlreport.py
+++ b/coverage/xmlreport.py
@@ -117,18 +117,18 @@ class XmlReporter(Reporter):
pct = 100.0 * (lhits_tot + bhits_tot) / denom
return pct
- def xml_file(self, cu, analysis):
+ def xml_file(self, fr, analysis):
"""Add to the XML report for a single file."""
# Create the 'lines' and 'package' XML elements, which
# are populated later. Note that a package == a directory.
- filename = self.file_locator.relative_filename(cu.filename)
+ filename = self.file_locator.relative_filename(fr.filename)
filename = filename.replace("\\", "/")
dirname = os.path.dirname(filename) or "."
parts = dirname.split("/")
dirname = "/".join(parts[:self.config.xml_package_depth])
package_name = dirname.replace("/", ".")
- className = cu.name
+ className = fr.name
self.source_paths.add(self.file_locator.relative_dir.rstrip('/'))
package = self.packages.setdefault(package_name, [{}, 0, 0, 0, 0])
diff --git a/lab/dataflow.txt b/lab/dataflow.txt
index b2b619a3..1f628f15 100644
--- a/lab/dataflow.txt
+++ b/lab/dataflow.txt
@@ -18,7 +18,7 @@ CoverageData.add_line_data( { filename: { lineno: None, .. }, ... } )
CoverageData.measured_files():
returns [filename, ...]
called by:
- Reporter.find_code_units()
+ Reporter.find_file_reporters()
tests
CoverageData.executed_lines():
diff --git a/tests/test_filereporter.py b/tests/test_filereporter.py
index 473bfe49..9db4c0c3 100644
--- a/tests/test_filereporter.py
+++ b/tests/test_filereporter.py
@@ -1,4 +1,4 @@
-"""Tests for coverage.codeunit"""
+"""Tests for FileReporters"""
import os
import sys