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 --- tests/test_html.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_html.py b/tests/test_html.py index b728847f..de967f86 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests that HTML generation is awesome.""" -import os.path, re +import os.path, re, sys import coverage import coverage.html from coverage.misc import CoverageException, NotPython, NoSource @@ -267,6 +267,27 @@ class HtmlWithUnparsableFilesTest(CoverageTest): cov.html_report() self.assert_exists("htmlcov/index.html") + if sys.version_info < (3, 0): + def test_decode_error(self): + # imp.load_module won't load a file with an undecodable character + # in a comment, though Python will run them. So we'll change the + # file after running. + self.make_file("main.py", "import sub.not_ascii") + self.make_file("sub/__init__.py") + self.make_file("sub/not_ascii.py", """\ + a = 1 # Isn't this great? + """) + cov = coverage.coverage() + self.start_import_stop(cov, "main") + + # Create the undecodable version of the file. + self.make_file("sub/not_ascii.py", """\ + a = 1 # Isn't this great?\xcb + """) + msg = r"Couldn't decode '.*sub/not_ascii.py' as ascii: .*\\xcb.*" + with self.assertRaisesRegex(CoverageException, msg): + cov.html_report() + class HtmlTest(CoverageTest): """Moar HTML tests.""" -- cgit v1.2.1