summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-02-07 16:37:14 -0500
committerNed Batchelder <ned@nedbatchelder.com>2010-02-07 16:37:14 -0500
commit34f71934dacede93f59b372fde4c5a646dbc702b (patch)
tree3c4f0c1704659d0b6e66a973a55b7c37a4229fc8
parentb79c9052164851e90603be595eddcbda25f7aadc (diff)
downloadpython-coveragepy-34f71934dacede93f59b372fde4c5a646dbc702b.tar.gz
Clean up the lst += string stuff, whereby string being iterable means each char is added as an element of the list. Also, apply the 'join is better than append' rule to other places, where, alas, it doesn't seem to have the same magic effect.
-rw-r--r--coverage/html.py30
-rw-r--r--coverage/htmlfiles/pyfile.html8
-rw-r--r--coverage/templite.py4
3 files changed, 21 insertions, 21 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 4d51eb3..39ee886 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -69,27 +69,27 @@ class HtmlReporter(Reporter):
arcs = self.arcs
# These classes determine which lines are highlighted by default.
- c_run = " run hide_run"
- c_exc = " exc"
- c_mis = " mis"
- c_par = " par" + c_run
+ c_run = "run hide_run"
+ c_exc = "exc"
+ c_mis = "mis"
+ c_par = "par " + c_run
lines = []
for lineno, line in enumerate(source_token_lines(source)):
lineno += 1 # 1-based line numbers.
# Figure out how to mark this line.
- line_class = ""
+ line_class = []
annotate_html = ""
annotate_title = ""
if lineno in analysis.statements:
- line_class += " stm"
+ line_class.append("stm")
if lineno in analysis.excluded:
- line_class += c_exc
+ line_class.append(c_exc)
elif lineno in analysis.missing:
- line_class += c_mis
+ line_class.append(c_mis)
elif self.arcs and lineno in missing_branch_arcs:
- line_class += c_par
+ line_class.append(c_par)
n_par += 1
annlines = []
for b in missing_branch_arcs[lineno]:
@@ -103,21 +103,21 @@ class HtmlReporter(Reporter):
elif len(annlines) == 1:
annotate_title = "no jump to this line number"
elif lineno in analysis.statements:
- line_class += c_run
+ line_class.append(c_run)
# Build the HTML for the line
- html = ""
+ html = []
for tok_type, tok_text in line:
if tok_type == "ws":
- html += escape(tok_text)
+ html.append(escape(tok_text))
else:
tok_html = escape(tok_text) or '&nbsp;'
- html += "<span class='%s'>%s</span>" % (tok_type, tok_html)
+ html.append("<span class='%s'>%s</span>" % (tok_type, tok_html))
lines.append({
- 'html': html,
+ 'html': ''.join(html),
'number': lineno,
- 'class': line_class.strip() or "pln",
+ 'class': ' '.join(line_class) or "pln",
'annotate': annotate_html,
'annotate_title': annotate_title,
})
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index 79808c3..ec69556 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -16,11 +16,11 @@
</h1>
<h2 class='stats'>
{{nums.n_statements}} statements
- <span class='{{c_run.strip}}' onclick='toggle_lines(this, "run")'>{{nums.n_executed}} run</span>
- <span class='{{c_exc.strip}}' onclick='toggle_lines(this, "exc")'>{{nums.n_excluded}} excluded</span>
- <span class='{{c_mis.strip}}' onclick='toggle_lines(this, "mis")'>{{nums.n_missing}} missing</span>
+ <span class='{{c_run}}' onclick='toggle_lines(this, "run")'>{{nums.n_executed}} run</span>
+ <span class='{{c_exc}}' onclick='toggle_lines(this, "exc")'>{{nums.n_excluded}} excluded</span>
+ <span class='{{c_mis}}' onclick='toggle_lines(this, "mis")'>{{nums.n_missing}} missing</span>
{% if arcs %}
- <span class='{{c_par.strip}}' onclick='toggle_lines(this, "par")'>{{n_par}} partial</span>
+ <span class='{{c_par}}' onclick='toggle_lines(this, "par")'>{{n_par}} partial</span>
{% endif %}
</h2>
</div>
diff --git a/coverage/templite.py b/coverage/templite.py
index 66f38a9..c39e061 100644
--- a/coverage/templite.py
+++ b/coverage/templite.py
@@ -118,10 +118,10 @@ class _TempliteEngine(object):
"""
for op, args in ops:
if op == 'lit':
- self.result += args
+ self.result.append(args)
elif op == 'exp':
try:
- self.result += str(self.evaluate(args))
+ self.result.append(str(self.evaluate(args)))
except:
exc_class, exc, _ = sys.exc_info()
new_exc = exc_class("Couldn't evaluate {{ %s }}: %s"