summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-06-09 12:53:43 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-06-09 12:53:43 -0400
commit7859afe0f96ec56ae2968bef1c20bbad0182ab22 (patch)
tree5f39227ec1454cafe069887798c5fb269c9d4be3 /tests
parentc246e197fa582854cd3165d47b3170cda425af1f (diff)
downloadpython-coveragepy-7859afe0f96ec56ae2968bef1c20bbad0182ab22.tar.gz
Add detail to the UnicodeDecodeError for #303
Diffstat (limited to 'tests')
-rw-r--r--tests/test_html.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/test_html.py b/tests/test_html.py
index b728847..de967f8 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."""