mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #18873: The tokenize module, IDLE, 2to3, and the findnocoding.py script
now detect Python source code encoding only in comment lines.
This commit is contained in:
parent
975fce3788
commit
dafea85190
9 changed files with 44 additions and 22 deletions
|
@ -946,6 +946,13 @@ class TestDetectEncoding(TestCase):
|
|||
readline = self.get_readline((b'# coding: bad\n',))
|
||||
self.assertRaises(SyntaxError, detect_encoding, readline)
|
||||
|
||||
def test_false_encoding(self):
|
||||
# Issue 18873: "Encoding" detected in non-comment lines
|
||||
readline = self.get_readline((b'print("#coding=fake")',))
|
||||
encoding, consumed_lines = detect_encoding(readline)
|
||||
self.assertEqual(encoding, 'utf-8')
|
||||
self.assertEqual(consumed_lines, [b'print("#coding=fake")'])
|
||||
|
||||
def test_open(self):
|
||||
filename = support.TESTFN + '.py'
|
||||
self.addCleanup(support.unlink, filename)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue