Issue #28512: Fixed setting the offset attribute of SyntaxError by

PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
This commit is contained in:
Serhiy Storchaka 2016-12-11 14:39:01 +02:00
parent 49c14d8e8f
commit 8b58339eb2
7 changed files with 56 additions and 58 deletions

View file

@ -540,7 +540,7 @@
class SyntaxTestCase(unittest.TestCase):
def _check_error(self, code, errtext,
filename="<testcase>", mode="exec", subclass=None):
filename="<testcase>", mode="exec", subclass=None, lineno=None, offset=None):
"""Check that compiling code raises SyntaxError with errtext.
errtest is a regular expression that must be present in the
@ -555,6 +555,11 @@ def _check_error(self, code, errtext,
mo = re.search(errtext, str(err))
if mo is None:
self.fail("SyntaxError did not contain '%r'" % (errtext,))
self.assertEqual(err.filename, filename)
if lineno is not None:
self.assertEqual(err.lineno, lineno)
if offset is not None:
self.assertEqual(err.offset, offset)
else:
self.fail("compile() did not raise SyntaxError")
@ -565,7 +570,7 @@ def test_assign_del(self):
self._check_error("del f()", "delete")
def test_global_err_then_warn(self):
# Bug tickler: The SyntaxError raised for one global statement
# Bug #763201: The SyntaxError raised for one global statement
# shouldn't be clobbered by a SyntaxWarning issued for a later one.
source = """if 1:
def error(a):
@ -575,7 +580,7 @@ def warning():
global b # SyntaxWarning
"""
warnings.filterwarnings(action='ignore', category=SyntaxWarning)
self._check_error(source, "global")
self._check_error(source, "global", lineno=3, offset=16)
warnings.filters.pop(0)
def test_break_outside_loop(self):