summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-08 17:29:21 -0700
committerGitHub <noreply@github.com>2021-06-09 01:29:21 +0100
commitc0496093e54edb78d2bd09b083b73e1e5b9e7242 (patch)
treef9f30b61fd77edb18e2030c32bbf5dabf0754035 /Lib
parenteeefa7f6c0cc64bc74c3b96a0ebbff1a2b9d3199 (diff)
downloadcpython-git-c0496093e54edb78d2bd09b083b73e1e5b9e7242.tar.gz
bpo-44349: Fix edge case when displaying text from files with encoding in syntax errors (GH-26611) (GH-26616)
(cherry picked from commit 9fd21f649d66dcb10108ee395fd68ed32c8239cd) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index df5778d7e5..b242c082f8 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -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)