From 44a4f8e24aedb956cf6540ddba432ef5655482df Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 21 Apr 2009 08:36:45 -0400 Subject: A table of statistics at the top of the page. --- coverage/html.py | 67 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 15 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 85f5c9a..9f109a8 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -22,10 +22,22 @@ class HtmlReporter(Reporter): def html_file(self, cu, statements, excluded, missing): """Generate an HTML file for one source file.""" - lines = [] source = cu.source_file() - for lineno, line in enumerate(source.readlines()): - lineno += 1 + source_lines = source.readlines() + + n_lin = len(source_lines) + n_stm = len(statements) + n_exc = len(excluded) + n_mis = len(missing) + if n_stm > 0: + pc_cov = 100.0 * float(n_mis) / n_stm + else: + pc_cov = 100.0 + + lines = [] + for lineno, line in enumerate(source_lines): + lineno += 1 # enum is 0-based, lines are 1-based. + css_class = "" if lineno in statements: @@ -65,6 +77,8 @@ def not_empty(t): """Make sure HTML content is not completely empty.""" return t or " " +def format_pct(p): + return "%.0f" % p # Templates @@ -77,15 +91,25 @@ SOURCE = """\ Coverage for {{cu.name|escape}}