summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/html.py185
-rw-r--r--coverage/htmlfiles/pyfile.html51
-rw-r--r--coverage/htmlfiles/style.css105
3 files changed, 175 insertions, 166 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 416c6879..40ed3168 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -1,10 +1,20 @@
"""HTML reporting for coverage.py"""
-import os
+import os, shutil
from coverage import __version__ # pylint: disable-msg=W0611
from coverage.report import Reporter
from coverage.templite import Templite
+
+def data_filename(fname):
+ """Return the path to a data file of ours."""
+ return os.path.join(os.path.split(__file__)[0], fname)
+
+def data(fname):
+ """Return the contents of a data file of ours."""
+ return open(data_filename(fname)).read()
+
+
class HtmlReporter(Reporter):
"""HTML reporting.
@@ -13,10 +23,17 @@ class HtmlReporter(Reporter):
def __init__(self, coverage, ignore_errors=False):
super(HtmlReporter, self).__init__(coverage, ignore_errors)
self.directory = None
- self.source_tmpl = Templite(SOURCE, globals())
+ self.source_tmpl = Templite(data("htmlfiles/pyfile.html"), globals())
def report(self, morfs, directory=None, omit_prefixes=None):
assert directory, "must provide a directory for html reporting"
+ # Create the once-per-directory files.
+ shutil.copyfile(
+ data_filename("htmlfiles/style.css"),
+ os.path.join(directory, "style.css")
+ )
+
+ # Process all the files.
self.report_files(self.html_file, morfs, directory, omit_prefixes)
def html_file(self, cu, statements, excluded, missing):
@@ -79,167 +96,3 @@ def not_empty(t):
def format_pct(p):
return "%.0f" % p
-
-# Templates
-
-# For making line numbers and text different fonts:
-# http://24ways.org/2006/compose-to-a-vertical-rhythm
-
-SOURCE = """\
-<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
-<title>Coverage for {{cu.name|escape}}</title>
-<style>
-/* Page-wide styles */
-html, body, p, td {
- margin: 0;
- padding: 0;
- }
-
-/* Set baseline grid to 14 pt. */
-body {
- font-size: .875em; /* 14/16 */
- }
-
-html>body {
- font-size: 14px;
- }
-
-/* Set base font size to 12/14 */
-p {
- font-size: .85714em; /* 12/14 */
- line-height: 1.16667em; /* 14/12 */
- }
-
-a.nav {
- text-decoration: none;
- color: inherit;
- }
-a.nav:hover {
- text-decoration: underline;
- color: inherit;
- }
-
-/* Page structure */
-#header {
- background: #ffd472;
- width: 100%;
- font-family: verdana, sans-serif;
- }
-
-#source {
- padding: 1em;
- font-family: "courier new", monospace;
- }
-
-#footer {
- background: #ffe9b8;
- font-size: 85%;
- font-family: verdana, sans-serif;
- color: #666666;
- font-style: italic;
- }
-
-/* Header styles */
-.content {
- padding: 1em;
- }
-
-#file_stats {
- float: right;
- }
-
-.stats .number {
- text-align: right;
- font-weight: bold;
- }
-
-/* Source file styles */
-.linenos {
- background: #eeeeee;
- }
-.linenos p {
- text-align: right;
- margin: 0;
- padding: 0 .5em;
- color: #999999;
- font-size: .75em; /* 9/12 */
- line-height: 1.3333em; /* 12/9, why isn't it 14/9? */
- }
-td.text {
- width: 100%;
- }
-.text p {
- margin: 0;
- padding: 0 0 0 .5em;
- white-space: nowrap;
- }
-
-.linenos p.mis {
- background: #ffcccc;
- }
-.linenos p.run {
- background: #ccffcc;
- }
-.linenos p.exc {
- background: #e2e2e2;
- }
-
-.text p.mis {
- background: #ffdddd;
- }
-.text p.run {
- background: #ddffdd;
- }
-.text p.exc {
- background: #eeeeee;
- }
-</style>
-</head>
-<body>
-<div id='header'>
- <div class='content'>
- <div id='file_stats'>
- <table class='stats'>
- <tr><td class='label'>Lines</td><td class='number'>{{n_lin}}</td></tr>
- <tr><td class='label'>Statements</td><td class='number'>{{n_stm}}</td></tr>
- <tr><td class='label'>Excluded</td><td class='number'>{{n_exc}}</td></tr>
- <tr><td class='label'>Missing</td><td class='number'>{{n_mis}}</td></tr>
- </table>
- </div>
- <p>Coverage for <b>{{cu.filename|escape}}</b>:
- <span class='pc_cov'>{{pc_cov|format_pct}}%</span>
- </p>
- <div style='clear:both'></div>
- </div>
-</div>
-
-<div id='source'>
-<table cellspacing='0' cellpadding='0'>
-<tr>
-<td class='linenos' valign='top'>
- {% for line in lines %}
- <p class='{{line.class}}'>{{line.number}}</p>
- {% endfor %}
-</td>
-<td class='text' valign='top'>
- {% for line in lines %}
- <p class='{{line.class}}'>{{line.text.rstrip|escape|not_empty}}</p>
- {% endfor %}
-</td>
-</tr>
-</table>
-</div>
-
-<div id='footer'>
- <div class='content'>
- <p>
- <a class='nav' href='http://bitbucket.org/ned/coveragepy/'>coverage.py v{{__version__}}</a>
- </p>
- </div>
-</div>
-
-</body>
-</html>
-"""
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
new file mode 100644
index 00000000..1a30d897
--- /dev/null
+++ b/coverage/htmlfiles/pyfile.html
@@ -0,0 +1,51 @@
+<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Coverage for {{cu.name|escape}}</title>
+<link rel='stylesheet' href='style.css' type='text/css'>
+</head>
+<body>
+<div id='header'>
+ <div class='content'>
+ <div id='file_stats'>
+ <table class='stats'>
+ <tr><td class='label'>Lines</td><td class='number'>{{n_lin}}</td></tr>
+ <tr><td class='label'>Statements</td><td class='number'>{{n_stm}}</td></tr>
+ <tr><td class='label'>Excluded</td><td class='number'>{{n_exc}}</td></tr>
+ <tr><td class='label'>Missing</td><td class='number'>{{n_mis}}</td></tr>
+ </table>
+ </div>
+ <p>Coverage for <b>{{cu.filename|escape}}</b>:
+ <span class='pc_cov'>{{pc_cov|format_pct}}%</span>
+ </p>
+ <div style='clear:both'></div>
+ </div>
+</div>
+
+<div id='source'>
+<table cellspacing='0' cellpadding='0'>
+<tr>
+<td class='linenos' valign='top'>
+ {% for line in lines %}
+ <p class='{{line.class}}'>{{line.number}}</p>
+ {% endfor %}
+</td>
+<td class='text' valign='top'>
+ {% for line in lines %}
+ <p class='{{line.class}}'>{{line.text.rstrip|escape|not_empty}}</p>
+ {% endfor %}
+</td>
+</tr>
+</table>
+</div>
+
+<div id='footer'>
+ <div class='content'>
+ <p>
+ <a class='nav' href='http://bitbucket.org/ned/coveragepy/'>coverage.py v{{__version__}}</a>
+ </p>
+ </div>
+</div>
+
+</body>
+</html>
diff --git a/coverage/htmlfiles/style.css b/coverage/htmlfiles/style.css
new file mode 100644
index 00000000..1fb9b6ba
--- /dev/null
+++ b/coverage/htmlfiles/style.css
@@ -0,0 +1,105 @@
+/* CSS styles for coverage.py */
+/* Page-wide styles */
+html, body, p, td {
+ margin: 0;
+ padding: 0;
+ }
+
+/* Set baseline grid to 14 pt. */
+body {
+ font-size: .875em; /* 14/16 */
+ }
+
+html>body {
+ font-size: 14px;
+ }
+
+/* Set base font size to 12/14 */
+p {
+ font-size: .85714em; /* 12/14 */
+ line-height: 1.16667em; /* 14/12 */
+ }
+
+a.nav {
+ text-decoration: none;
+ color: inherit;
+ }
+a.nav:hover {
+ text-decoration: underline;
+ color: inherit;
+ }
+
+/* Page structure */
+#header {
+ background: #ffd472;
+ width: 100%;
+ font-family: verdana, sans-serif;
+ }
+
+#source {
+ padding: 1em;
+ font-family: "courier new", monospace;
+ }
+
+#footer {
+ background: #ffe9b8;
+ font-size: 85%;
+ font-family: verdana, sans-serif;
+ color: #666666;
+ font-style: italic;
+ }
+
+/* Header styles */
+.content {
+ padding: 1em;
+ }
+
+#file_stats {
+ float: right;
+ }
+
+.stats .number {
+ text-align: right;
+ font-weight: bold;
+ }
+
+/* Source file styles */
+.linenos {
+ background: #eeeeee;
+ }
+.linenos p {
+ text-align: right;
+ margin: 0;
+ padding: 0 .5em;
+ color: #999999;
+ font-size: .75em; /* 9/12 */
+ line-height: 1.3333em; /* 12/9, why isn't it 14/9? */
+ }
+td.text {
+ width: 100%;
+ }
+.text p {
+ margin: 0;
+ padding: 0 0 0 .5em;
+ white-space: nowrap;
+ }
+
+.linenos p.mis {
+ background: #ffcccc;
+ }
+.linenos p.run {
+ background: #ccffcc;
+ }
+.linenos p.exc {
+ background: #e2e2e2;
+ }
+
+.text p.mis {
+ background: #ffdddd;
+ }
+.text p.run {
+ background: #ddffdd;
+ }
+.text p.exc {
+ background: #eeeeee;
+ }