summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt11
-rw-r--r--coverage/html.py4
-rw-r--r--coverage/htmlfiles/index.html6
-rw-r--r--coverage/htmlfiles/pyfile.html4
-rw-r--r--coverage/results.py17
-rw-r--r--coverage/summary.py6
-rw-r--r--test/farm/run/run_xxx.py2
-rw-r--r--test/test_coverage.py2
-rw-r--r--test/test_results.py10
-rw-r--r--test/test_summary.py2
10 files changed, 49 insertions, 15 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index d9de9e07..1af4d9ea 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,17 @@ Change history for Coverage.py
------------------------------
+Version 3.4b2
+-------------
+
+- Coverage percentages are now displayed uniformly across reporting methods. A
+ percentage is only reported as 0% or 100% if they are truly 0 or 100, and
+ are rounded otherwise. Fixes `issue 41` and issue 70`.
+
+.. _issue 70: http://bitbucket.org/ned/coveragepy/issue/70/text-report-and-html-report-disagree-on-coverage
+.. _issue 41: http://bitbucket.org/ned/coveragepy/issue/41/report-says-100-when-it-isnt-quite-there
+
+
Version 3.4b1 --- 21 August 2010
--------------------------------
diff --git a/coverage/html.py b/coverage/html.py
index fc6d8016..9ca4dea0 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -174,10 +174,6 @@ def escape(t):
.replace(" ", "  ")
)
-def format_pct(p):
- """Format `p` as a percentage value for the HTML reports."""
- return "%.0f" % p
-
def spaceless(html):
"""Squeeze out some annoying extra space from an HTML string.
diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html
index c1ef8ad7..bec2584f 100644
--- a/coverage/htmlfiles/index.html
+++ b/coverage/htmlfiles/index.html
@@ -16,7 +16,7 @@
<div id='header'>
<div class='content'>
<h1>Coverage report:
- <span class='pc_cov'>{{totals.pc_covered|format_pct}}%</span>
+ <span class='pc_cov'>{{totals.pc_covered_str}}%</span>
</h1>
</div>
</div>
@@ -48,7 +48,7 @@
<td>{{totals.n_branches}}</td>
<td>{{totals.n_missing_branches}}</td>
{% endif %}
- <td class='right'>{{totals.pc_covered|format_pct}}%</td>
+ <td class='right'>{{totals.pc_covered_str}}%</td>
</tr>
</tfoot>
<tbody>
@@ -62,7 +62,7 @@
<td>{{file.nums.n_branches}}</td>
<td>{{file.nums.n_missing_branches}}</td>
{% endif %}
- <td class='right'>{{file.nums.pc_covered|format_pct}}%</td>
+ <td class='right'>{{file.nums.pc_covered_str}}%</td>
</tr>
{% endfor %}
</tbody>
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index 035691c8..05b2b464 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -5,7 +5,7 @@
{# IE8 rounds line-height incorrectly, and adding this emulateIE7 line makes it right! #}
{# http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/7684445e-f080-4d8f-8529-132763348e21 #}
<meta http-equiv='X-UA-Compatible' content='IE=emulateIE7' />
- <title>Coverage for {{cu.name|escape}}: {{nums.pc_covered|format_pct}}%</title>
+ <title>Coverage for {{cu.name|escape}}: {{nums.pc_covered_str}}%</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='coverage_html.js'></script>
@@ -18,7 +18,7 @@
<div id='header'>
<div class='content'>
<h1>Coverage for <b>{{cu.name|escape}}</b> :
- <span class='pc_cov'>{{nums.pc_covered|format_pct}}%</span>
+ <span class='pc_cov'>{{nums.pc_covered_str}}%</span>
</h1>
<h2 class='stats'>
{{nums.n_statements}} statements
diff --git a/coverage/results.py b/coverage/results.py
index e80ec0a4..a3bdec15 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -157,6 +157,23 @@ class Numbers(object):
return pc_cov
pc_covered = property(_get_pc_covered)
+ def _get_pc_covered_str(self):
+ """Returns the percent covered, as a string, without a percent sign.
+
+ The important thing here is that "0" only be returned when it's truly
+ zero, and "100" only be returned when it's truly 100.
+
+ """
+ pc = self.pc_covered
+ if 0 < pc < 1:
+ pc = 1.0
+ elif 99 < pc < 100:
+ pc = 99.0
+ else:
+ pc = round(pc)
+ return "%.0f" % pc
+ pc_covered_str = property(_get_pc_covered_str)
+
def __add__(self, other):
nums = Numbers()
nums.n_files = self.n_files + other.n_files
diff --git a/coverage/summary.py b/coverage/summary.py
index 37039bab..53c844d1 100644
--- a/coverage/summary.py
+++ b/coverage/summary.py
@@ -32,7 +32,7 @@ class SummaryReporter(Reporter):
header += " Branch BrPart"
fmt_coverage += " %6d %6d"
header += " Cover"
- fmt_coverage += " %5d%%"
+ fmt_coverage += " %5s%%"
if self.show_missing:
header += " Missing"
fmt_coverage += " %s"
@@ -56,7 +56,7 @@ class SummaryReporter(Reporter):
args = (cu.name, nums.n_statements, nums.n_missing)
if self.branches:
args += (nums.n_branches, nums.n_missing_branches)
- args += (nums.pc_covered,)
+ args += (nums.pc_covered_str,)
if self.show_missing:
args += (analysis.missing_formatted(),)
outfile.write(fmt_coverage % args)
@@ -73,7 +73,7 @@ class SummaryReporter(Reporter):
args = ("TOTAL", total.n_statements, total.n_missing)
if self.branches:
args += (total.n_branches, total.n_missing_branches)
- args += (total.pc_covered,)
+ args += (total.pc_covered_str,)
if self.show_missing:
args += ("",)
outfile.write(fmt_coverage % args)
diff --git a/test/farm/run/run_xxx.py b/test/farm/run/run_xxx.py
index 27967a9f..19e94a42 100644
--- a/test/farm/run/run_xxx.py
+++ b/test/farm/run/run_xxx.py
@@ -6,7 +6,7 @@ run("""
contains("out/stdout.txt",
"xxx: 3 4 0 7",
"\nxxx ", # The reporting line for xxx
- " 7 1 85%" # The reporting data for xxx
+ " 7 1 86%" # The reporting data for xxx
)
doesnt_contain("out/stdout.txt", "No such file or directory")
clean("out")
diff --git a/test/test_coverage.py b/test/test_coverage.py
index 4fd54494..31f3aa17 100644
--- a/test/test_coverage.py
+++ b/test/test_coverage.py
@@ -663,7 +663,7 @@ class CompoundStatementTest(CoverageTest):
y = 5
assert x == 3
""",
- [1,2,3,4,5,6], "4-5", report="6 2 66% 4-5")
+ [1,2,3,4,5,6], "4-5", report="6 2 67% 4-5")
self.check_coverage("""\
a = 1; b = 2; c = 3;
if a != 1:
diff --git a/test/test_results.py b/test/test_results.py
index ef15121c..79beb4e9 100644
--- a/test/test_results.py
+++ b/test/test_results.py
@@ -39,3 +39,13 @@ class NumbersTest(CoverageTest):
self.assertEqual(n3.n_executed, 182)
self.assertEqual(n3.n_missing, 28)
self.assertAlmostEqual(n3.pc_covered, 86.666666666)
+
+ def test_pc_covered_str(self):
+ n0 = Numbers(n_files=1, n_statements=1000, n_missing=0)
+ n1 = Numbers(n_files=1, n_statements=1000, n_missing=1)
+ n999 = Numbers(n_files=1, n_statements=1000, n_missing=999)
+ n1000 = Numbers(n_files=1, n_statements=1000, n_missing=1000)
+ self.assertEqual(n0.pc_covered_str, "100")
+ self.assertEqual(n1.pc_covered_str, "99")
+ self.assertEqual(n999.pc_covered_str, "1")
+ self.assertEqual(n1000.pc_covered_str, "0")
diff --git a/test/test_summary.py b/test/test_summary.py
index 0d7db402..db440f85 100644
--- a/test/test_summary.py
+++ b/test/test_summary.py
@@ -109,7 +109,7 @@ class SummaryTest(CoverageTest):
self.assertEqual(self.line_count(report), 3)
self.assertTrue("mybranch " in report)
self.assertEqual(self.last_line_squeezed(report),
- "mybranch 5 0 2 1 85%")
+ "mybranch 5 0 2 1 86%")
class SummaryTest2(CoverageTest):
"""Another bunch of summary tests."""