summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-11-02 11:10:19 -0500
committerNed Batchelder <ned@nedbatchelder.com>2009-11-02 11:10:19 -0500
commitf6bc21ddee35703d80914d245f06ee5ce594eb97 (patch)
tree6bc33549d11dc4d1d830344e81b5501ded61d936 /coverage
parent467eb680940b8653667751f4232a3d46f61d8350 (diff)
downloadpython-coveragepy-git-f6bc21ddee35703d80914d245f06ee5ce594eb97.tar.gz
HTML reporting makes use of Numbers to simplify and centralize the code.
Diffstat (limited to 'coverage')
-rw-r--r--coverage/html.py27
-rw-r--r--coverage/htmlfiles/index.html18
-rw-r--r--coverage/htmlfiles/pyfile.html10
-rw-r--r--coverage/results.py20
4 files changed, 35 insertions, 40 deletions
diff --git a/coverage/html.py b/coverage/html.py
index c653cf9c..b5923351 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -1,8 +1,9 @@
"""HTML reporting for Coverage."""
import keyword, os, re, token, tokenize, shutil
-from coverage import __url__, __version__ # pylint: disable-msg=W0611
-from coverage.backward import StringIO # pylint: disable-msg=W0622
+
+from coverage import __url__, __version__ # pylint: disable-msg=W0611
+from coverage.backward import StringIO # pylint: disable-msg=W0622
from coverage.report import Reporter
from coverage.templite import Templite
@@ -88,12 +89,8 @@ class HtmlReporter(Reporter):
source = cu.source_file().read().expandtabs(4)
source_lines = source.split("\n")
-
- n_stm = len(analysis.statements)
- n_exc = len(analysis.excluded)
- n_mis = len(analysis.missing)
- n_run = n_stm - n_mis
- pc_cov = analysis.numbers.percent_covered
+
+ nums = analysis.numbers
missing_branch_arcs = analysis.missing_branch_arcs()
n_par = 0 # accumulated below.
@@ -170,12 +167,8 @@ class HtmlReporter(Reporter):
# Save this file's information for the index file.
self.files.append({
- 'stm': n_stm,
- 'run': n_run,
- 'exc': n_exc,
- 'mis': n_mis,
+ 'nums': nums,
'par': n_par,
- 'pc_cov': pc_cov,
'html_filename': html_filename,
'cu': cu,
})
@@ -187,14 +180,8 @@ class HtmlReporter(Reporter):
files = self.files
arcs = self.arcs
- total_stm = sum([f['stm'] for f in files])
- total_run = sum([f['run'] for f in files])
- total_exc = sum([f['exc'] for f in files])
+ totals = sum([f['nums'] for f in files])
total_par = sum([f['par'] for f in files])
- if total_stm:
- total_cov = 100.0 * total_run / total_stm
- else:
- total_cov = 100.0
fhtml = open(os.path.join(self.directory, "index.html"), "w")
fhtml.write(index_tmpl.render(locals()))
diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html
index 03a83cc3..1e11e9e1 100644
--- a/coverage/htmlfiles/index.html
+++ b/coverage/htmlfiles/index.html
@@ -10,7 +10,7 @@
<div id='header'>
<div class='content'>
<h1>Coverage report:
- <span class='pc_cov'>{{total_cov|format_pct}}%</span>
+ <span class='pc_cov'>{{totals.percent_covered|format_pct}}%</span>
</h1>
</div>
</div>
@@ -30,24 +30,24 @@
{% for file in files %}
<tr class='file'>
<td class='name'><a href='{{file.html_filename}}'>{{file.cu.name}}</a></td>
- <td>{{file.stm}}</td>
- <td>{{file.run}}</td>
- <td>{{file.exc}}</td>
+ <td>{{file.nums.n_statements}}</td>
+ <td>{{file.nums.n_run}}</td>
+ <td>{{file.nums.n_excluded}}</td>
{% if arcs %}
<td>{{file.par}}</td>
{% endif %}
- <td>{{file.pc_cov|format_pct}}%</td>
+ <td>{{file.nums.percent_covered|format_pct}}%</td>
</tr>
{% endfor %}
<tr class='total'>
<td class='name'>Total</td>
-<td>{{total_stm}}</td>
-<td>{{total_run}}</td>
-<td>{{total_exc}}</td>
+<td>{{totals.n_statements}}</td>
+<td>{{totals.n_run}}</td>
+<td>{{totals.n_excluded}}</td>
{% if arcs %}
<td>{{total_par}}</td>
{% endif %}
-<td>{{total_cov|format_pct}}%</td>
+<td>{{totals.percent_covered|format_pct}}%</td>
</tr>
</table>
</div>
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index e2ec19c3..5c9509bc 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -23,13 +23,13 @@ function toggle_lines(btn, cls) {
<div id='header'>
<div class='content'>
<h1>Coverage for <b>{{cu.name|escape}}</b> :
- <span class='pc_cov'>{{pc_cov|format_pct}}%</span>
+ <span class='pc_cov'>{{nums.percent_covered|format_pct}}%</span>
</h1>
<h2 class='stats'>
- {{n_stm}} statements
- <span class='{{c_run.strip}}' onclick='toggle_lines(this, "run")'>{{n_run}} run</span>
- <span class='{{c_exc.strip}}' onclick='toggle_lines(this, "exc")'>{{n_exc}} excluded</span>
- <span class='{{c_mis.strip}}' onclick='toggle_lines(this, "mis")'>{{n_mis}} missing</span>
+ {{nums.n_statements}} statements
+ <span class='{{c_run.strip}}' onclick='toggle_lines(this, "run")'>{{nums.n_run}} run</span>
+ <span class='{{c_exc.strip}}' onclick='toggle_lines(this, "exc")'>{{nums.n_excluded}} excluded</span>
+ <span class='{{c_mis.strip}}' onclick='toggle_lines(this, "mis")'>{{nums.n_missing}} missing</span>
{% if arcs %}
<span class='{{c_par.strip}}' onclick='toggle_lines(this, "par")'>{{n_par}} partial</span>
{% endif %}
diff --git a/coverage/results.py b/coverage/results.py
index 41102595..ec59482d 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -125,6 +125,7 @@ class Numbers(object):
self.n_missing = 0
def _get_n_run(self):
+ """Returns the number of executed statements."""
return self.n_statements - self.n_missing
n_run = property(_get_n_run)
@@ -137,9 +138,16 @@ class Numbers(object):
return pc_cov
percent_covered = property(_get_percent_covered)
- def __iadd__(self, other):
- self.n_files += other.n_files
- self.n_statements += other.n_statements
- self.n_excluded += other.n_excluded
- self.n_missing += other.n_missing
- return self
+ def __add__(self, other):
+ nums = Numbers()
+ nums.n_files = self.n_files + other.n_files
+ nums.n_statements = self.n_statements + other.n_statements
+ nums.n_excluded = self.n_excluded + other.n_excluded
+ nums.n_missing = self.n_missing + other.n_missing
+ return nums
+
+ def __radd__(self, other):
+ # Implementing 0+Numbers allows us to sum() a list of Numbers.
+ if other == 0:
+ return self
+ raise NotImplemented