summaryrefslogtreecommitdiff
path: root/coverage/html.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/html.py')
-rw-r--r--coverage/html.py90
1 files changed, 55 insertions, 35 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 3877c834..94ba0dea 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -18,38 +18,44 @@ def data_filename(fname):
def data(fname):
"""Return the contents of a data file of ours."""
return open(data_filename(fname)).read()
-
+
class HtmlReporter(Reporter):
"""HTML reporting."""
-
+
def __init__(self, coverage, ignore_errors=False):
super(HtmlReporter, self).__init__(coverage, ignore_errors)
self.directory = None
self.source_tmpl = Templite(data("htmlfiles/pyfile.html"), globals())
-
+
self.files = []
self.arcs = coverage.data.has_arcs()
- def report(self, morfs, directory, omit_prefixes=None):
+ def report(self, morfs, directory, omit_prefixes=None,
+ include_prefixes=None
+ ):
"""Generate an HTML report for `morfs`.
-
+
`morfs` is a list of modules or filenames. `directory` is where to put
- the HTML files. `omit_prefixes` is a list of strings, prefixes of
- modules to omit from the report.
-
+ the HTML files.
+
+ See `coverage.report()` for other arguments.
+
"""
assert directory, "must provide a directory for html reporting"
-
+
# Process all the files.
- self.report_files(self.html_file, morfs, directory, omit_prefixes)
+ self.report_files(
+ self.html_file, morfs, directory, omit_prefixes, include_prefixes
+ )
# Write the index file.
self.index_file()
# Create the once-per-directory files.
for static in [
- "style.css", "jquery-1.3.2.min.js", "jquery.tablesorter.min.js"
+ "style.css", "coverage_html.js",
+ "jquery-1.3.2.min.js", "jquery.tablesorter.min.js"
]:
shutil.copyfile(
data_filename("htmlfiles/" + static),
@@ -58,55 +64,69 @@ class HtmlReporter(Reporter):
def html_file(self, cu, analysis):
"""Generate an HTML file for one source file."""
-
+
source = cu.source_file().read()
- nums = analysis.numbers
+ nums = analysis.numbers
missing_branch_arcs = analysis.missing_branch_arcs()
n_par = 0 # accumulated below.
arcs = self.arcs
# These classes determine which lines are highlighted by default.
- c_run = " run hide"
- c_exc = " exc"
- c_mis = " mis"
- c_par = " par"
+ c_run = "run hide_run"
+ c_exc = "exc"
+ c_mis = "mis"
+ c_par = "par " + c_run
lines = []
-
+
for lineno, line in enumerate(source_token_lines(source)):
lineno += 1 # 1-based line numbers.
# Figure out how to mark this line.
- line_class = ""
- annotate = ""
+ line_class = []
+ annotate_html = ""
+ annotate_title = ""
if lineno in analysis.statements:
- line_class += " stm"
+ line_class.append("stm")
if lineno in analysis.excluded:
- line_class += c_exc
+ line_class.append(c_exc)
elif lineno in analysis.missing:
- line_class += c_mis
+ line_class.append(c_mis)
elif self.arcs and lineno in missing_branch_arcs:
- line_class += c_par
+ line_class.append(c_par)
n_par += 1
- annotate = " ".join(map(str, missing_branch_arcs[lineno]))
+ annlines = []
+ for b in missing_branch_arcs[lineno]:
+ if b < 0:
+ annlines.append("exit")
+ else:
+ annlines.append(str(b))
+ annotate_html = "&nbsp;&nbsp; ".join(annlines)
+ if len(annlines) > 1:
+ annotate_title = "no jumps to these line numbers"
+ elif len(annlines) == 1:
+ annotate_title = "no jump to this line number"
elif lineno in analysis.statements:
- line_class += c_run
-
+ line_class.append(c_run)
+
# Build the HTML for the line
- html = ""
+ html = []
for tok_type, tok_text in line:
if tok_type == "ws":
- html += escape(tok_text)
+ html.append(escape(tok_text))
else:
tok_html = escape(tok_text) or '&nbsp;'
- html += "<span class='%s'>%s</span>" % (tok_type, tok_html)
+ html.append(
+ "<span class='%s'>%s</span>" % (tok_type, tok_html)
+ )
lines.append({
- 'html': html,
+ 'html': ''.join(html),
'number': lineno,
- 'class': line_class.strip() or "pln",
- 'annotate': annotate,
+ 'class': ' '.join(line_class) or "pln",
+ 'annotate': annotate_html,
+ 'annotate_title': annotate_title,
})
# Write the HTML page for this file.
@@ -160,10 +180,10 @@ def format_pct(p):
def spaceless(html):
"""Squeeze out some annoying extra space from an HTML string.
-
+
Nicely-formatted templates mean lots of extra space in the result. Get
rid of some.
-
+
"""
html = re.sub(">\s+<p ", ">\n<p ", html)
return html