summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-06-10 09:01:00 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-06-10 09:01:00 -0400
commit17b6fe064c3e93df5561fa181e191f37ea7f0bbf (patch)
treec6abee7e299cb656d991fc062e71179277e23832
parent6d79cab810cac3e7350c9dcbafbf51453b63efba (diff)
downloadpython-coveragepy-git-17b6fe064c3e93df5561fa181e191f37ea7f0bbf.tar.gz
Expand tabs to spaces before creating HTML output. Fixes bug #6.
-rw-r--r--coverage/html.py2
-rw-r--r--test/farm/html/run_tabbed.py18
-rw-r--r--test/farm/html/src/tabbed.py8
3 files changed, 28 insertions, 0 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 7e1e544a..5d2c561c 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -140,6 +140,8 @@ class HtmlReporter(Reporter):
def escape(t):
"""HTML-escape the text in t."""
return (t
+ # Change all tabs to 4 spaces.
+ .expandtabs(4)
# Convert HTML special chars into HTML entities.
.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
.replace("'", "&#39;").replace('"', "&quot;")
diff --git a/test/farm/html/run_tabbed.py b/test/farm/html/run_tabbed.py
new file mode 100644
index 00000000..c49bdfbd
--- /dev/null
+++ b/test/farm/html/run_tabbed.py
@@ -0,0 +1,18 @@
+def html_it():
+ """Run coverage and make an HTML report for tabbed."""
+ import coverage
+ cov = coverage.coverage()
+ cov.start()
+ import tabbed
+ cov.stop()
+ cov.html_report(tabbed, directory="../html")
+
+runfunc(html_it, rundir="src")
+
+# Editors like to change things, make sure our source file still has tabs.
+contains("src/tabbed.py", "\tif x:\t\t\t\t\t\t# look nice")
+
+contains("html/tabbed.html",
+ "<p class='stm run hide'>&nbsp; &nbsp; if x:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; # look nice</p>")
+doesnt_contain("html/tabbed.html", "\t")
+clean("html")
diff --git a/test/farm/html/src/tabbed.py b/test/farm/html/src/tabbed.py
new file mode 100644
index 00000000..fe426115
--- /dev/null
+++ b/test/farm/html/src/tabbed.py
@@ -0,0 +1,8 @@
+# This file should have tabs.
+x = 1
+if x:
+ a = "Tabbed" # Aligned comments
+ if x: # look nice
+ b = "No spaces" # when they
+ c = "Done" # line up.
+