summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-12-11 12:39:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-12-11 12:39:01 (GMT)
commit8b58339eb2939da4df822f7ea457b44e120fad45 (patch)
treed34029d80314da5bea6e6fccbc9f07e74fa50457 /Lib/test/support
parent49c14d8e8fe8f1897eef72ef45665b7afeec32d6 (diff)
downloadcpython-8b58339eb2939da4df822f7ea457b44e120fad45.zip
cpython-8b58339eb2939da4df822f7ea457b44e120fad45.tar.gz
cpython-8b58339eb2939da4df822f7ea457b44e120fad45.tar.bz2
Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 698f503..d0d126a 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1041,9 +1041,16 @@ def make_bad_fd():
file.close()
unlink(TESTFN)
-def check_syntax_error(testcase, statement):
- testcase.assertRaises(SyntaxError, compile, statement,
- '<test string>', 'exec')
+def check_syntax_error(testcase, statement, *, lineno=None, offset=None):
+ with testcase.assertRaises(SyntaxError) as cm:
+ compile(statement, '<test string>', 'exec')
+ err = cm.exception
+ testcase.assertIsNotNone(err.lineno)
+ if lineno is not None:
+ testcase.assertEqual(err.lineno, lineno)
+ testcase.assertIsNotNone(err.offset)
+ if offset is not None:
+ testcase.assertEqual(err.offset, offset)
def open_urlresource(url, *args, **kw):
import urllib.request, urllib.parse