diff Lib/test/test_importlib/source/test_source_encoding.py @ 85731:2dfe8262093c 3.3

Issue #18873: The tokenize module, IDLE, 2to3, and the findnocoding.py script now detect Python source code encoding only in comment lines.
author Serhiy Storchaka <storchaka@gmail.com>
date Mon, 16 Sep 2013 23:51:56 +0300
parents 4cebcfc97774
children b0f570aef6fd
line wrap: on
line diff
--- a/Lib/test/test_importlib/source/test_source_encoding.py	Mon Sep 16 11:01:31 2013 +0300
+++ b/Lib/test/test_importlib/source/test_source_encoding.py	Mon Sep 16 23:51:56 2013 +0300
@@ -10,7 +10,7 @@
 import unittest
 
 
-CODING_RE = re.compile(r'coding[:=]\s*([-\w.]+)')
+CODING_RE = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)', re.ASCII)
 
 
 class EncodingTest(unittest.TestCase):
@@ -41,7 +41,7 @@
 
     def create_source(self, encoding):
         encoding_line = "# coding={0}".format(encoding)
-        assert CODING_RE.search(encoding_line)
+        assert CODING_RE.match(encoding_line)
         source_lines = [encoding_line.encode('utf-8')]
         source_lines.append(self.source_line.encode(encoding))
         return b'\n'.join(source_lines)
@@ -50,7 +50,7 @@
         # Make sure that an encoding that has never been a standard one for
         # Python works.
         encoding_line = "# coding=koi8-r"
-        assert CODING_RE.search(encoding_line)
+        assert CODING_RE.match(encoding_line)
         source = "{0}\na=42\n".format(encoding_line).encode("koi8-r")
         self.run_test(source)