From 670ce62b70c50a4e84bc185e42998c860565a5fc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 24 Dec 2015 09:24:11 -0500 Subject: Add a failing test of double coding declarations, for #453 --- tests/test_phystokens.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index e28fb176..7acc3225 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -103,6 +103,7 @@ ENCODING_DECLARATION_SOURCES = [ b"# This Python file uses this encoding: cp850\n", b"# This file uses a different encoding:\n# coding: cp850\n", b"\n# coding=cp850\n\n", + b"# -*- coding:cp850 -*-\n# vim: fileencoding=cp850\n", ] class SourceEncodingTest(CoverageTest): @@ -168,6 +169,8 @@ class NeuterEncodingDeclarationTest(CoverageTest): ) self.assertEqual(lines_different, 1) + # The neutered source will be detected as having no encoding + # declaration. self.assertEqual( source_encoding(neutered), DEF_ENCODING, @@ -181,5 +184,9 @@ class CompileUnicodeTest(CoverageTest): run_in_temp_dir = False def test_cp1252(self): - uni = u"""# coding: cp1252\n# \u201C curly \u201D\n""" - compile_unicode(uni, "", "exec") + uni = u"""# coding: cp1252\n# \u201C curly \u201D\na = 42""" + # This doesn't raise an exception: + code = compile_unicode(uni, "", "exec") + globs = {} + exec(code, globs) + self.assertEqual(globs['a'], 42) -- cgit v1.2.1