diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-05 08:50:36 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-05 08:50:36 -0400 |
commit | 01e0d8ad49d74e93e00748a309f9a54b8a91307e (patch) | |
tree | ac76fe85c37be40e391ebfde0dfef8db668d11f2 /tests/test_phystokens.py | |
parent | c9ee7976fe1c1126c1a6f8e23b0f8fc68c091e6f (diff) | |
download | python-coveragepy-01e0d8ad49d74e93e00748a309f9a54b8a91307e.tar.gz |
A fix for coding declarations, bug #529
Diffstat (limited to 'tests/test_phystokens.py')
-rw-r--r-- | tests/test_phystokens.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index ccbe01b..68456b5 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -5,6 +5,7 @@ import os.path import re +import textwrap from coverage import env from coverage.phystokens import source_token_lines, source_encoding @@ -177,6 +178,63 @@ class NeuterEncodingDeclarationTest(CoverageTest): "Wrong encoding in %r" % neutered ) + def test_two_encoding_declarations(self): + input_src = textwrap.dedent(u"""\ + # -*- coding: ascii -*- + # -*- coding: utf-8 -*- + # -*- coding: utf-16 -*- + """) + expected_src = textwrap.dedent(u"""\ + # (deleted declaration) -*- + # (deleted declaration) -*- + # -*- coding: utf-16 -*- + """) + output_src = neuter_encoding_declaration(input_src) + self.assertEqual(expected_src, output_src) + + def test_one_encoding_declaration(self): + input_src = textwrap.dedent(u"""\ + # -*- coding: utf-16 -*- + # Just a comment. + # -*- coding: ascii -*- + """) + expected_src = textwrap.dedent(u"""\ + # (deleted declaration) -*- + # Just a comment. + # -*- coding: ascii -*- + """) + output_src = neuter_encoding_declaration(input_src) + self.assertEqual(expected_src, output_src) + + +class Bug529Test(CoverageTest): + """Test of bug 529""" + + def test_bug_529(self): + self.make_file("the_test.py", '''\ + # -*- coding: utf-8 -*- + import unittest + class FailsUnderCoverageTest(unittest.TestCase): + def test_fails_under_coverage(self): + src1 = u"""\\ + # -*- coding: utf-8 -*- + # Just a comment. + """ + src2 = u"""\\ + # -*- coding: utf-8 -*- + # Just a comment. + """ + self.assertEqual(src1, src2) + + if __name__ == "__main__": + unittest.main() + ''') + status, out = self.run_command_status("coverage run the_test.py") + self.assertEqual(status, 0) + self.assertIn("OK", out) + # If this test fails, the output will be super-confusing, because it + # has a failing unit test contained within the failing unit test. + class CompileUnicodeTest(CoverageTest): """Tests of compiling Unicode strings.""" |