mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-44349: Fix edge case when displaying text from files with encoding in syntax errors (GH-26611)
This commit is contained in:
parent
2ea6d89028
commit
9fd21f649d
3 changed files with 22 additions and 2 deletions
|
@ -2105,6 +2105,22 @@ class SyntaxErrorTests(unittest.TestCase):
|
|||
sys.__excepthook__(*sys.exc_info())
|
||||
the_exception = exc
|
||||
|
||||
def test_encodings(self):
|
||||
source = (
|
||||
'# -*- coding: cp437 -*-\n'
|
||||
'"¢¢¢¢¢¢" + f(4, x for x in range(1))\n'
|
||||
)
|
||||
try:
|
||||
with open(TESTFN, 'w', encoding='cp437') as testfile:
|
||||
testfile.write(source)
|
||||
rc, out, err = script_helper.assert_python_failure('-Wd', '-X', 'utf8', TESTFN)
|
||||
err = err.decode('utf-8').splitlines()
|
||||
|
||||
self.assertEqual(err[-3], ' "¢¢¢¢¢¢" + f(4, x for x in range(1))')
|
||||
self.assertEqual(err[-2], ' ^^^^^^^^^^^^^^^^^^^')
|
||||
finally:
|
||||
unlink(TESTFN)
|
||||
|
||||
def test_attributes_new_constructor(self):
|
||||
args = ("bad.py", 1, 2, "abcdefg", 1, 100)
|
||||
the_exception = SyntaxError("bad bad", args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue