From a189b3bb1846d8e0c7b003a94af69822d3890f9e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 21:26:57 -0400 Subject: Continued refactoring of CodeUnit --- coverage/html.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 15afca8e..159ae581 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -148,9 +148,7 @@ class HtmlReporter(Reporter): def html_file(self, cu, analysis): """Generate an HTML file for one source file.""" - source_file = cu.source_file() - with source_file: - source = source_file.read() + source = cu.source() # Find out if the file on disk is already correct. flat_rootname = cu.flat_rootname() -- cgit v1.2.1 From 8f5aa5738644bf81c2d0547de5bbe5f77548b1a9 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 9 Jun 2014 12:53:43 -0400 Subject: Add detail to the UnicodeDecodeError for #303 --- coverage/html.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 159ae581..6c811107 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -238,7 +238,15 @@ class HtmlReporter(Reporter): })) if sys.version_info < (3, 0): - html = html.decode(encoding) + try: + html = html.decode(encoding) + except UnicodeDecodeError as e: + sample = e.object[max([0, e.start-30]):e.start+30] + raise CoverageException( + "Couldn't decode %r as %s: %r" % ( + cu.filename, e.encoding, sample + ) + ) html_filename = flat_rootname + ".html" html_path = os.path.join(self.directory, html_filename) -- cgit v1.2.1 From be5178fda38750c0aae78061bf1b1bf3397a467d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 11 Jun 2014 22:02:32 -0400 Subject: Prevent UnicodeDecodeErrors in html report. #303 --- coverage/html.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 6c811107..85f47ab4 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -238,15 +238,9 @@ class HtmlReporter(Reporter): })) if sys.version_info < (3, 0): - try: - html = html.decode(encoding) - except UnicodeDecodeError as e: - sample = e.object[max([0, e.start-30]):e.start+30] - raise CoverageException( - "Couldn't decode %r as %s: %r" % ( - cu.filename, e.encoding, sample - ) - ) + # In theory, all the characters in the source can be decoded, but + # strange things happen, so use 'replace' to keep errors at bay. + html = html.decode(encoding, 'replace') html_filename = flat_rootname + ".html" html_path = os.path.join(self.directory, html_filename) -- cgit v1.2.1