diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-11 14:39:01 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-11 14:39:01 +0200 |
commit | 8b58339eb2939da4df822f7ea457b44e120fad45 (patch) | |
tree | d34029d80314da5bea6e6fccbc9f07e74fa50457 /Lib/test/test_syntax.py | |
parent | 49c14d8e8fe8f1897eef72ef45665b7afeec32d6 (diff) | |
download | cpython-git-8b58339eb2939da4df822f7ea457b44e120fad45.tar.gz |
Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r-- | Lib/test/test_syntax.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 83f49f6580..301c142d75 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -540,7 +540,7 @@ from test import support 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 @@ class SyntaxTestCase(unittest.TestCase): 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 @@ class SyntaxTestCase(unittest.TestCase): 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 @@ class SyntaxTestCase(unittest.TestCase): 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): |