summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-02-01 20:25:13 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-02-01 20:25:13 -0500
commit51b6d237bbaf7fe19c073d80277b6b34187cca3e (patch)
treef7a84f0c254997b8445cea2ab7b57504098ac791
parente2e3e0f3f43535a2bccf432ca0f7bba6191faa8e (diff)
downloadpython-coveragepy-git-51b6d237bbaf7fe19c073d80277b6b34187cca3e.tar.gz
Use whitespace:pre to avoid having to convert spaces in the HTML report. Fixes #472.
-rw-r--r--CHANGES.rst6
-rw-r--r--coverage/html.py19
-rw-r--r--coverage/htmlfiles/style.css2
-rw-r--r--tests/test_html.py24
4 files changed, 23 insertions, 28 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 775c4566..63f2c9a8 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -22,10 +22,12 @@ Unreleased
Shishov.
- The HTML report now uses different monospaced fonts, favoring Consolas over
- Courier. The index page also has slightly different styling, to try to make
- the clickable detail pages more apparent.
+ Courier. Along the way, `issue 472`_ about not properly handling one-space
+ indents was fixed. The index page also has slightly different styling, to
+ try to make the clickable detail pages more apparent.
.. _issue 440: https://bitbucket.org/ned/coveragepy/issues/440/yielded-twisted-failure-marked-as-missed
+.. _issue 472: https://bitbucket.org/ned/coveragepy/issues/472/html-report-indents-incorrectly-for-one
Version 4.1b2 --- 2016-01-23
diff --git a/coverage/html.py b/coverage/html.py
index 8dca6323..6a2132b7 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -418,18 +418,13 @@ class HtmlStatus(object):
# Helpers for templates and generating HTML
def escape(t):
- """HTML-escape the text in `t`."""
- return (
- t
- # Convert HTML special chars into HTML entities.
- .replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
- .replace("'", "&#39;").replace('"', "&quot;")
- # Convert runs of spaces: "......" -> "&nbsp;.&nbsp;.&nbsp;."
- .replace(" ", "&nbsp; ")
- # To deal with odd-length runs, convert the final pair of spaces
- # so that "....." -> "&nbsp;.&nbsp;&nbsp;."
- .replace(" ", "&nbsp; ")
- )
+ """HTML-escape the text in `t`.
+
+ This is only suitable for HTML text, not attributes.
+
+ """
+ # Convert HTML special chars into HTML entities.
+ return t.replace("&", "&amp;").replace("<", "&lt;")
def spaceless(html):
diff --git a/coverage/htmlfiles/style.css b/coverage/htmlfiles/style.css
index 186b085b..4f43b591 100644
--- a/coverage/htmlfiles/style.css
+++ b/coverage/htmlfiles/style.css
@@ -226,7 +226,7 @@ td.text {
margin: 0;
padding: 0 0 0 .5em;
border-left: 2px solid #ffffff;
- white-space: nowrap;
+ white-space: pre;
}
.text p.mis {
diff --git a/tests/test_html.py b/tests/test_html.py
index 11f0979a..97a7c6ab 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -341,7 +341,7 @@ class HtmlWithUnparsableFilesTest(HtmlTestHelpers, CoverageTest):
cov.html_report()
html_report = self.get_html_report_content("sub/not_ascii.py")
- expected = "# Isn&#39;t this great?&#65533;!"
+ expected = "# Isn't this great?&#65533;!"
self.assertIn(expected, html_report)
def test_formfeeds(self):
@@ -494,7 +494,7 @@ class HtmlGoldTests(CoverageGoldTest):
"out/a/a_py.html",
('<span class="key">if</span> <span class="num">1</span> '
'<span class="op">&lt;</span> <span class="num">2</span>'),
- ('&nbsp; &nbsp; <span class="nam">a</span> '
+ (' <span class="nam">a</span> '
'<span class="op">=</span> <span class="num">3</span>'),
'<span class="pc_cov">67%</span>',
)
@@ -521,7 +521,7 @@ class HtmlGoldTests(CoverageGoldTest):
"out/b_branch/b_py.html",
('<span class="key">if</span> <span class="nam">x</span> '
'<span class="op">&lt;</span> <span class="num">2</span>'),
- ('&nbsp; &nbsp; <span class="nam">a</span> <span class="op">=</span> '
+ (' <span class="nam">a</span> <span class="op">=</span> '
'<span class="num">3</span>'),
'<span class="pc_cov">70%</span>',
('<span class="annotate" title="Line 8 was executed, but never jumped to line 11">'
@@ -553,7 +553,7 @@ class HtmlGoldTests(CoverageGoldTest):
compare("gold_bom", "out/bom", size_within=10, file_pattern="*.html")
contains(
"out/bom/bom_py.html",
- '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
+ '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
)
def test_isolatin1(self):
@@ -570,7 +570,7 @@ class HtmlGoldTests(CoverageGoldTest):
compare("gold_isolatin1", "out/isolatin1", size_within=10, file_pattern="*.html")
contains(
"out/isolatin1/isolatin1_py.html",
- '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
+ '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
)
def test_omit_1(self):
@@ -708,7 +708,7 @@ class HtmlGoldTests(CoverageGoldTest):
'<link rel="stylesheet" href="extra.css" type="text/css">',
('<span class="key">if</span> <span class="num">1</span> '
'<span class="op">&lt;</span> <span class="num">2</span>'),
- ('&nbsp; &nbsp; <span class="nam">a</span> <span class="op">=</span> '
+ (' <span class="nam">a</span> <span class="op">=</span> '
'<span class="num">3</span>'),
'<span class="pc_cov">67%</span>'
)
@@ -735,10 +735,9 @@ class HtmlGoldTests(CoverageGoldTest):
contains(
"out/tabbed/tabbed_py.html",
- '>&nbsp; &nbsp; &nbsp; &nbsp; <span class="key">if</span> '
+ '> <span class="key">if</span> '
'<span class="nam">x</span><span class="op">:</span>'
- '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '
- '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; '
+ ' '
'<span class="com"># look nice</span>'
)
@@ -758,12 +757,11 @@ class HtmlGoldTests(CoverageGoldTest):
compare("gold_unicode", "out/unicode", size_within=10, file_pattern="*.html")
contains(
"out/unicode/unicode_py.html",
- ('<span class="str">&quot;&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;&quot;'
- '</span>'),
+ '<span class="str">"&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;"</span>',
)
contains_any(
"out/unicode/unicode_py.html",
- '<span class="str">&quot;db40,dd00: x&#56128;&#56576;&quot;</span>',
- '<span class="str">&quot;db40,dd00: x&#917760;&quot;</span>',
+ '<span class="str">"db40,dd00: x&#56128;&#56576;"</span>',
+ '<span class="str">"db40,dd00: x&#917760;"</span>',
)