summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_eof.py
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2021-01-20 21:38:47 (GMT)
committerGitHub <noreply@github.com>2021-01-20 21:38:47 (GMT)
commita698d52c3975c80b45b139b2f08402ec514dce75 (patch)
tree25a4577b9617d80cb43ffcfe27a54435f42c6b0d /Lib/test/test_eof.py
parentc3f167d7b243f8b8e1b797586e6cef35add013bc (diff)
downloadcpython-a698d52c3975c80b45b139b2f08402ec514dce75.zip
cpython-a698d52c3975c80b45b139b2f08402ec514dce75.tar.gz
cpython-a698d52c3975c80b45b139b2f08402ec514dce75.tar.bz2
bpo-40176: Improve error messages for unclosed string literals (GH-19346)
Automerge-Triggered-By: GH:isidentical
Diffstat (limited to 'Lib/test/test_eof.py')
-rw-r--r--Lib/test/test_eof.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/Lib/test/test_eof.py b/Lib/test/test_eof.py
index 2cf263d..b370e27 100644
--- a/Lib/test/test_eof.py
+++ b/Lib/test/test_eof.py
@@ -7,23 +7,25 @@ from test.support import script_helper
import unittest
class EOFTestCase(unittest.TestCase):
- def test_EOFC(self):
- expect = "EOL while scanning string literal (<string>, line 1)"
- try:
- eval("""'this is a test\
- """)
- except SyntaxError as msg:
- self.assertEqual(str(msg), expect)
- else:
- raise support.TestFailed
+ def test_EOF_single_quote(self):
+ expect = "unterminated string literal (detected at line 1) (<string>, line 1)"
+ for quote in ("'", "\""):
+ try:
+ eval(f"""{quote}this is a test\
+ """)
+ except SyntaxError as msg:
+ self.assertEqual(str(msg), expect)
+ self.assertEqual(msg.offset, 1)
+ else:
+ raise support.TestFailed
def test_EOFS(self):
- expect = ("EOF while scanning triple-quoted string literal "
- "(<string>, line 1)")
+ expect = ("unterminated triple-quoted string literal (detected at line 1) (<string>, line 1)")
try:
eval("""'''this is a test""")
except SyntaxError as msg:
self.assertEqual(str(msg), expect)
+ self.assertEqual(msg.offset, 1)
else:
raise support.TestFailed