diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-11 12:44:21 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-11 12:44:21 (GMT) |
commit | 26817a84908b831d71dd59de432f75829a5bae33 (patch) | |
tree | 155827823d4c5c344adbae096cbbe2f634263b45 /Lib/test/support | |
parent | 2b27c2ddbaee778b4de128bd43359b66dcda01f8 (diff) | |
parent | 8114f21668fe9775d2542d079c6396a745f4f094 (diff) | |
download | cpython-26817a84908b831d71dd59de432f75829a5bae33.zip cpython-26817a84908b831d71dd59de432f75829a5bae33.tar.gz cpython-26817a84908b831d71dd59de432f75829a5bae33.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__.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 1f664f6..6df48c0 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1060,9 +1060,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 |