summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-11-15 17:53:24 -0500
committerNed Batchelder <ned@nedbatchelder.com>2009-11-15 17:53:24 -0500
commit7bdce80a45920e3888ac0366fdbfb54c6604eba6 (patch)
tree7fe9a9a28931e25d0cc93ea5b27c80ec07951724
parent47da566616f14caad010da58f4899a58ebc0b4ae (diff)
downloadpython-coveragepy-git-7bdce80a45920e3888ac0366fdbfb54c6604eba6.tar.gz
Tabs are 8 spaces, as the Python docs dictate. Fixes issue #31.
-rw-r--r--CHANGES.txt5
-rw-r--r--coverage/html.py2
-rw-r--r--coverage/phystokens.py2
-rw-r--r--test/farm/html/run_tabbed.py10
-rw-r--r--test/farm/html/src/tabbed.py4
-rw-r--r--test/test_phystokens.py26
6 files changed, 37 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 55f4f0af..d630b76b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,10 +5,11 @@ Change history for Coverage.py
Version 3.2b2
-------------
-- Fixed some problems syntax coloring sources with line continuations:
- `issue 30`_.
+- Fixed some problems syntax coloring sources with line continuations and
+ source with tabs: `issue 30`_ and `issue 31`_.
.. _issue 30: http://bitbucket.org/ned/coveragepy/issue/30
+.. _issue 31: http://bitbucket.org/ned/coveragepy/issue/31
Version 3.2b1, 10 November 2009
diff --git a/coverage/html.py b/coverage/html.py
index 98d32cdc..8c274728 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -60,7 +60,7 @@ class HtmlReporter(Reporter):
def html_file(self, cu, analysis):
"""Generate an HTML file for one source file."""
- source = cu.source_file().read().expandtabs(4)
+ source = cu.source_file().read()
nums = analysis.numbers
diff --git a/coverage/phystokens.py b/coverage/phystokens.py
index 7eebb8ad..2862490f 100644
--- a/coverage/phystokens.py
+++ b/coverage/phystokens.py
@@ -71,7 +71,7 @@ def source_token_lines(source):
ws_tokens = [token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL]
line = []
col = 0
- tokgen = tokenize.generate_tokens(StringIO(source).readline)
+ tokgen = tokenize.generate_tokens(StringIO(source.expandtabs(8)).readline)
for ttype, ttext, (_, scol), (_, ecol), _ in phys_tokens(tokgen):
mark_start = True
for part in re.split('(\n)', ttext):
diff --git a/test/farm/html/run_tabbed.py b/test/farm/html/run_tabbed.py
index 88ffcaef..e7e60cec 100644
--- a/test/farm/html/run_tabbed.py
+++ b/test/farm/html/run_tabbed.py
@@ -10,12 +10,14 @@ def html_it():
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("src/tabbed.py", "\tif x:\t\t\t\t\t# look nice")
contains("html/tabbed.html",
- ">&nbsp; &nbsp; <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; <span class='com'># look nice</span>"
+ ">&nbsp; &nbsp; &nbsp; &nbsp; <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>"
)
doesnt_contain("html/tabbed.html", "\t")
diff --git a/test/farm/html/src/tabbed.py b/test/farm/html/src/tabbed.py
index fe426115..bc6bb456 100644
--- a/test/farm/html/src/tabbed.py
+++ b/test/farm/html/src/tabbed.py
@@ -2,7 +2,7 @@
x = 1
if x:
a = "Tabbed" # Aligned comments
- if x: # look nice
+ if x: # look nice
b = "No spaces" # when they
- c = "Done" # line up.
+ c = "Done" # line up.
diff --git a/test/test_phystokens.py b/test/test_phystokens.py
index 64316034..ccbdb5a0 100644
--- a/test/test_phystokens.py
+++ b/test/test_phystokens.py
@@ -14,8 +14,15 @@ def foo():
say('two = %d' % 2)
"""
+MIXED_WS = """\
+def hello():
+ a="Hello world!"
+\tb="indented"
+"""
+
HERE = os.path.split(__file__)[0]
+
class PhysTokensTest(CoverageTest):
"""Tests for Coverage.py's improver tokenizer."""
@@ -51,14 +58,29 @@ class PhysTokensTest(CoverageTest):
[('ws', ' '), ('nam', 'say'), ('op', '('),
('str', "'two = %d'"), ('ws', ' '), ('op', '%'),
('ws', ' '), ('num', '2'), ('op', ')')]
- ]
- )
+ ])
self.check_tokenization(SIMPLE)
+ def test_tab_indentation(self):
+ # Mixed tabs and spaces...
+ self.assertEqual(list(source_token_lines(MIXED_WS)),
+ [
+ [('key', 'def'), ('ws', ' '), ('nam', 'hello'), ('op', '('),
+ ('op', ')'), ('op', ':')],
+ [('ws', ' '), ('nam', 'a'), ('op', '='),
+ ('str', '"Hello world!"')],
+ [('ws', ' '), ('nam', 'b'), ('op', '='),
+ ('str', '"indented"')],
+ ])
+
def test_tokenize_real_file(self):
+ # Check the tokenization of a real file (large, btw).
real_file = os.path.join(HERE, "test_coverage.py")
self.check_file_tokenization(real_file)
def test_stress(self):
+ # Check the tokenization of a stress-test file.
stress = os.path.join(HERE, "stress_phystoken.txt")
self.check_file_tokenization(stress)
+
+ \ No newline at end of file