diff options
author | Ned Batchelder <nedbat@gmail.com> | 2015-04-24 21:06:26 -0400 |
---|---|---|
committer | Ned Batchelder <nedbat@gmail.com> | 2015-04-24 21:06:26 -0400 |
commit | 4cac18d36cd53c85f43ab79816b71cd2d4a3e6db (patch) | |
tree | 5741c738325d92c1a417b2c943f9b3f98f3417ba /coverage/html.py | |
parent | 3d88444cd3659fb93f17cbf4288c23bc82f33ead (diff) | |
parent | c3a98ff12933710d751ec28b984edb7936d457d3 (diff) | |
download | python-coveragepy-4cac18d36cd53c85f43ab79816b71cd2d4a3e6db.tar.gz |
Merged in lep/coverage.py (pull request #48)
Fix #363: crash when annotating non-ascii characters in python 2.
Diffstat (limited to 'coverage/html.py')
-rw-r--r-- | coverage/html.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/coverage/html.py b/coverage/html.py index 2a9e0d1..0b2cc25 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals +import datetime import json import os import re @@ -92,6 +93,7 @@ class HtmlReporter(Reporter): self.status = HtmlStatus() self.extra_css = None self.totals = Numbers() + self.time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M') def report(self, morfs): """Generate an HTML report for `morfs`. @@ -150,20 +152,20 @@ class HtmlReporter(Reporter): with open(fname, "wb") as fout: fout.write(html.encode('ascii', 'xmlcharrefreplace')) - def file_hash(self, source, cu): + def file_hash(self, source, fr): """Compute a hash that changes if the file needs to be re-reported.""" m = Hasher() m.update(source) - self.coverage.data.add_to_hash(cu.filename, m) + self.coverage.data.add_to_hash(fr.filename, m) return m.hexdigest() - def html_file(self, cu, analysis): + def html_file(self, fr, analysis): """Generate an HTML file for one source file.""" - source = cu.source() + source = fr.source() # Find out if the file on disk is already correct. - flat_rootname = cu.flat_rootname() - this_hash = self.file_hash(source.encode('utf-8'), cu) + flat_rootname = fr.flat_rootname() + this_hash = self.file_hash(source.encode('utf-8'), fr) that_hash = self.status.file_hash(flat_rootname) if this_hash == that_hash: # Nothing has changed to require the file to be reported again. @@ -186,7 +188,7 @@ class HtmlReporter(Reporter): lines = [] - for lineno, line in enumerate(cu.source_token_lines(), start=1): + for lineno, line in enumerate(fr.source_token_lines(), start=1): # Figure out how to mark this line. line_class = [] annotate_html = "" @@ -221,7 +223,7 @@ class HtmlReporter(Reporter): else: tok_html = escape(tok_text) or ' ' html.append( - "<span class='%s'>%s</span>" % (tok_type, tok_html) + '<span class="%s">%s</span>' % (tok_type, tok_html) ) lines.append({ @@ -236,7 +238,8 @@ class HtmlReporter(Reporter): template_values = { 'c_exc': c_exc, 'c_mis': c_mis, 'c_par': c_par, 'c_run': c_run, 'arcs': self.arcs, 'extra_css': self.extra_css, - 'cu': cu, 'nums': nums, 'lines': lines, + 'fr': fr, 'nums': nums, 'lines': lines, + 'time_stamp': self.time_stamp, } html = spaceless(self.source_tmpl.render(template_values)) @@ -248,7 +251,7 @@ class HtmlReporter(Reporter): index_info = { 'nums': nums, 'html_filename': html_filename, - 'name': cu.name, + 'name': fr.name, } self.files.append(index_info) self.status.set_index_info(flat_rootname, index_info) @@ -266,6 +269,7 @@ class HtmlReporter(Reporter): 'extra_css': self.extra_css, 'files': self.files, 'totals': self.totals, + 'time_stamp': self.time_stamp, }) self.write_html( |