From f66e3cc366e0a50041bf782cf66c4096b39dbdd0 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 31 Oct 2015 11:10:29 -0400 Subject: Fix the non-ascii filename tests on windows (?) --- tests/helpers.py | 5 +++++ tests/test_process.py | 50 +++++++++++++++++++++++++------------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/tests/helpers.py b/tests/helpers.py index f0859f51..d652fe8e 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -7,6 +7,8 @@ import os import subprocess import sys +from coverage import env + def run_command(cmd): """Run a command in a sub-process. @@ -14,6 +16,9 @@ def run_command(cmd): Returns the exit status code and the combined stdout and stderr. """ + if env.PY2 and isinstance(cmd, unicode): + cmd = cmd.encode(sys.getfilesystemencoding()) + # In some strange cases (PyPy3 in a virtualenv!?) the stdout encoding of # the subprocess is set incorrectly to ascii. Use an environment variable # to force the encoding to be the same as ours. diff --git a/tests/test_process.py b/tests/test_process.py index 8f69877f..e1bd2bf3 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -887,74 +887,74 @@ class FailUnderEmptyFilesTest(CoverageTest): class UnicodeFilePathsTest(CoverageTest): """Tests of using non-ascii characters in the names of files.""" - def test_snowman_dot_py(self): + def test_accented_dot_py(self): # Make a file with a non-ascii character in the filename. - self.make_file(u"snowman☃.py", "print('snowman')") - out = self.run_command(u"coverage run snowman☃.py") - self.assertEqual(out, "snowman\n") + self.make_file(u"h\xe2t.py", "print('accented')") + out = self.run_command(u"coverage run h\xe2t.py") + self.assertEqual(out, "accented\n") # The HTML report uses ascii-encoded HTML entities. out = self.run_command("coverage html") self.assertEqual(out, "") - self.assert_exists("htmlcov/snowman☃_py.html") + self.assert_exists(u"htmlcov/h\xe2t_py.html") with open("htmlcov/index.html") as indexf: index = indexf.read() - self.assertIn('snowman☃.py', index) + self.assertIn('hât.py', index) # The XML report is always UTF8-encoded. out = self.run_command("coverage xml") self.assertEqual(out, "") with open("coverage.xml", "rb") as xmlf: xml = xmlf.read() - self.assertIn(u' filename="snowman☃.py"'.encode('utf8'), xml) - self.assertIn(u' name="snowman☃.py"'.encode('utf8'), xml) + self.assertIn(u' filename="h\xe2t.py"'.encode('utf8'), xml) + self.assertIn(u' name="h\xe2t.py"'.encode('utf8'), xml) report_expected = ( - u"Name Stmts Miss Cover\n" - u"---------------------------------\n" - u"snowman☃.py 1 0 100%\n" + u"Name Stmts Miss Cover\n" + u"----------------------------\n" + u"h\xe2t.py 1 0 100%\n" ) if env.PY2: - report_expected = report_expected.encode("utf8") + report_expected = report_expected.encode(sys.__stdout__.encoding) out = self.run_command("coverage report") self.assertEqual(out, report_expected) - def test_snowman_directory(self): + def test_accented_directory(self): # Make a file with a non-ascii character in the directory name. - self.make_file(u"☃/snowman.py", "print('snowman')") - out = self.run_command(u"coverage run ☃/snowman.py") - self.assertEqual(out, "snowman\n") + self.make_file(u"\xe2/accented.py", "print('accented')") + out = self.run_command(u"coverage run \xe2/accented.py") + self.assertEqual(out, "accented\n") # The HTML report uses ascii-encoded HTML entities. out = self.run_command("coverage html") self.assertEqual(out, "") - self.assert_exists("htmlcov/☃_snowman_py.html") + self.assert_exists(u"htmlcov/\xe2_accented_py.html") with open("htmlcov/index.html") as indexf: index = indexf.read() - self.assertIn('☃/snowman.py', index) + self.assertIn('â%saccented.py' % os.sep, index) # The XML report is always UTF8-encoded. out = self.run_command("coverage xml") self.assertEqual(out, "") with open("coverage.xml", "rb") as xmlf: xml = xmlf.read() - self.assertIn(u' filename="☃/snowman.py"'.encode('utf8'), xml) - self.assertIn(u' name="snowman.py"'.encode('utf8'), xml) + self.assertIn(u' filename="\xe2/accented.py"'.encode('utf8'), xml) + self.assertIn(u' name="accented.py"'.encode('utf8'), xml) self.assertIn( - u''.encode('utf8'), + u''.encode('utf8'), xml ) report_expected = ( - u"Name Stmts Miss Cover\n" - u"----------------------------------\n" - u"☃/snowman.py 1 0 100%\n" + u"Name Stmts Miss Cover\n" + u"-----------------------------------\n" + u"\xe2%saccented.py 1 0 100%%\n" % os.sep ) if env.PY2: - report_expected = report_expected.encode("utf8") + report_expected = report_expected.encode(sys.__stdout__.encoding) out = self.run_command("coverage report") self.assertEqual(out, report_expected) -- cgit v1.2.1