summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2012-04-20 17:37:11 -0400
committerNed Batchelder <ned@nedbatchelder.com>2012-04-20 17:37:11 -0400
commit78e2c8c6e014b205e5f2cf7764ca9cf3597b318a (patch)
tree99dcb9b259c8c343e1623c705dda50201b7b0d82 /coverage
parent886c61c219b68dd66103a8c05f96ae9bf6b82ad6 (diff)
downloadpython-coveragepy-git-78e2c8c6e014b205e5f2cf7764ca9cf3597b318a.tar.gz
The [html]extra_css configuration value is a file path to a CSS file that gets copied into the HTML report.
Diffstat (limited to 'coverage')
-rw-r--r--coverage/config.py3
-rw-r--r--coverage/control.py11
-rw-r--r--coverage/html.py15
-rw-r--r--coverage/htmlfiles/index.html3
-rw-r--r--coverage/htmlfiles/pyfile.html3
5 files changed, 33 insertions, 2 deletions
diff --git a/coverage/config.py b/coverage/config.py
index ef45ba5a..49d74e7a 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -52,6 +52,7 @@ class CoverageConfig(object):
# Defaults for [html]
self.html_dir = "htmlcov"
+ self.extra_css = None
# Defaults for [xml]
self.xml_output = "coverage.xml"
@@ -125,6 +126,8 @@ class CoverageConfig(object):
# [html]
if cp.has_option('html', 'directory'):
self.html_dir = cp.get('html', 'directory')
+ if cp.has_option('html', 'extra_css'):
+ self.extra_css = cp.get('html', 'extra_css')
# [xml]
if cp.has_option('xml', 'output'):
diff --git a/coverage/control.py b/coverage/control.py
index 7373b316..c21d885e 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -582,15 +582,22 @@ class coverage(object):
reporter.report(morfs, directory=directory)
def html_report(self, morfs=None, directory=None, ignore_errors=None,
- omit=None, include=None):
+ omit=None, include=None, extra_css=None):
"""Generate an HTML report.
+ The HTML is written to `directory`. The file "index.html" is the
+ overview starting point, with links to more detailed pages for
+ individual modules.
+
+ `extra_css` is a path to a file of other CSS to apply on the page.
+ It will be copied into the HTML directory.
+
See `coverage.report()` for other arguments.
"""
self.config.from_args(
ignore_errors=ignore_errors, omit=omit, include=include,
- html_dir=directory,
+ html_dir=directory, extra_css=extra_css,
)
reporter = HtmlReporter(self, self.config)
reporter.report(morfs)
diff --git a/coverage/html.py b/coverage/html.py
index af27edfa..f39bf949 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -58,6 +58,7 @@ class HtmlReporter(Reporter):
self.files = []
self.arcs = self.coverage.data.has_arcs()
self.status = HtmlStatus()
+ self.extra_css = None
def report(self, morfs):
"""Generate an HTML report for `morfs`.
@@ -78,6 +79,10 @@ class HtmlReporter(Reporter):
self.status.reset()
self.status.set_settings_hash(these_settings)
+ # The user may have extra CSS they want copied.
+ if self.config.extra_css:
+ self.extra_css = os.path.basename(self.config.extra_css)
+
# Process all the files.
self.report_files(self.html_file, morfs, self.config.html_dir)
@@ -91,12 +96,20 @@ class HtmlReporter(Reporter):
def make_local_static_report_files(self):
"""Make local instances of static files for HTML report."""
+ # The files we provide must always be copied.
for static in self.STATIC_FILES:
shutil.copyfile(
data_filename("htmlfiles/" + static),
os.path.join(self.directory, static)
)
+ # The user may have extra CSS they want copied.
+ if self.extra_css:
+ shutil.copyfile(
+ self.config.extra_css,
+ os.path.join(self.directory, self.extra_css)
+ )
+
def write_html(self, fname, html):
"""Write `html` to `fname`, properly encoded."""
fout = open(fname, "wb")
@@ -202,6 +215,7 @@ class HtmlReporter(Reporter):
# Write the HTML page for this file.
html_filename = flat_rootname + ".html"
html_path = os.path.join(self.directory, html_filename)
+ extra_css = self.extra_css
html = spaceless(self.source_tmpl.render(locals()))
if sys.version_info < (3, 0):
@@ -228,6 +242,7 @@ class HtmlReporter(Reporter):
arcs = self.arcs
totals = sum([f['nums'] for f in files])
+ extra_css = self.extra_css
self.write_html(
os.path.join(self.directory, "index.html"),
diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html
index 04b314a3..c6d9eec0 100644
--- a/coverage/htmlfiles/index.html
+++ b/coverage/htmlfiles/index.html
@@ -4,6 +4,9 @@
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage report</title>
<link rel='stylesheet' href='style.css' type='text/css'>
+ {% if extra_css %}
+ <link rel='stylesheet' href='{{ extra_css }}' type='text/css'>
+ {% endif %}
<script type='text/javascript' src='jquery-1.4.3.min.js'></script>
<script type='text/javascript' src='jquery.tablesorter.min.js'></script>
<script type='text/javascript' src='jquery.hotkeys.js'></script>
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index ee0a3b1b..434edfdd 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -7,6 +7,9 @@
<meta http-equiv='X-UA-Compatible' content='IE=emulateIE7' />
<title>Coverage for {{cu.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'>
+ {% endif %}
<script type='text/javascript' src='jquery-1.4.3.min.js'></script>
<script type='text/javascript' src='jquery.hotkeys.js'></script>
<script type='text/javascript' src='jquery.isonscreen.js'></script>