summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/source
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-09-16 20:51:56 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-09-16 20:51:56 (GMT)
commitdafea851901fc1de278ad79727d3b44f46ba5a31 (patch)
tree5f8d95de4856502e61c78168e7918776b161e9b4 /Lib/test/test_importlib/source
parent975fce37883899a55bbcdaa6300c5c6ffe9d3db2 (diff)
downloadcpython-dafea851901fc1de278ad79727d3b44f46ba5a31.zip
cpython-dafea851901fc1de278ad79727d3b44f46ba5a31.tar.gz
cpython-dafea851901fc1de278ad79727d3b44f46ba5a31.tar.bz2
Issue #18873: The tokenize module, IDLE, 2to3, and the findnocoding.py script
now detect Python source code encoding only in comment lines.
Diffstat (limited to 'Lib/test/test_importlib/source')
-rw-r--r--Lib/test/test_importlib/source/test_source_encoding.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/test/test_importlib/source/test_source_encoding.py b/Lib/test/test_importlib/source/test_source_encoding.py
index 0ca5195..ba02b44 100644
--- a/Lib/test/test_importlib/source/test_source_encoding.py
+++ b/Lib/test/test_importlib/source/test_source_encoding.py
@@ -10,7 +10,7 @@ import unicodedata
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 @@ class EncodingTest(unittest.TestCase):
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 @@ class EncodingTest(unittest.TestCase):
# 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)