From f6bc21ddee35703d80914d245f06ee5ce594eb97 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 2 Nov 2009 11:10:19 -0500 Subject: HTML reporting makes use of Numbers to simplify and centralize the code. --- coverage/html.py | 27 +++++++-------------------- coverage/htmlfiles/index.html | 18 +++++++++--------- coverage/htmlfiles/pyfile.html | 10 +++++----- coverage/results.py | 20 ++++++++++++++------ 4 files changed, 35 insertions(+), 40 deletions(-) (limited to 'coverage') 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 @@ @@ -30,24 +30,24 @@ {% for file in files %} {{file.cu.name}} - {{file.stm}} - {{file.run}} - {{file.exc}} + {{file.nums.n_statements}} + {{file.nums.n_run}} + {{file.nums.n_excluded}} {% if arcs %} {{file.par}} {% endif %} - {{file.pc_cov|format_pct}}% + {{file.nums.percent_covered|format_pct}}% {% endfor %} Total -{{total_stm}} -{{total_run}} -{{total_exc}} +{{totals.n_statements}} +{{totals.n_run}} +{{totals.n_excluded}} {% if arcs %} {{total_par}} {% endif %} -{{total_cov|format_pct}}% +{{totals.percent_covered|format_pct}}% 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) {