diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-06-09 12:53:43 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-06-09 12:53:43 -0400 |
commit | 8f5aa5738644bf81c2d0547de5bbe5f77548b1a9 (patch) | |
tree | 6b99da1894232262c2ac310f760b7ded8a9c3350 /tests/test_html.py | |
parent | cc2b678e7452395e58e3df43116b06c3410bec06 (diff) | |
download | python-coveragepy-git-8f5aa5738644bf81c2d0547de5bbe5f77548b1a9.tar.gz |
Add detail to the UnicodeDecodeError for #303
Diffstat (limited to 'tests/test_html.py')
-rw-r--r-- | tests/test_html.py | 23 |
1 files changed, 22 insertions, 1 deletions
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.""" |