diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-11 12:39:01 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-11 12:39:01 (GMT) |
commit | 8b58339eb2939da4df822f7ea457b44e120fad45 (patch) | |
tree | d34029d80314da5bea6e6fccbc9f07e74fa50457 /Lib/test/test_future.py | |
parent | 49c14d8e8fe8f1897eef72ef45665b7afeec32d6 (diff) | |
download | cpython-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/test_future.py')
-rw-r--r-- | Lib/test/test_future.py | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py index beac993..7b072ad 100644 --- a/Lib/test/test_future.py +++ b/Lib/test/test_future.py @@ -2,6 +2,7 @@ import unittest from test import support +import os import re rx = re.compile('\((\S+).py, line (\d+)') @@ -12,6 +13,12 @@ def get_error_location(msg): class FutureTest(unittest.TestCase): + def check_syntax_error(self, err, basename, lineno, offset=0): + self.assertIn('%s.py, line %d' % (basename, lineno), str(err)) + self.assertEqual(os.path.basename(err.filename), basename + '.py') + self.assertEqual(err.lineno, lineno) + self.assertEqual(err.offset, offset) + def test_future1(self): with support.CleanImport('future_test1'): from test import future_test1 @@ -27,68 +34,44 @@ class FutureTest(unittest.TestCase): from test import test_future3 def test_badfuture3(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future3 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future3", 3) def test_badfuture4(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future4 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future4", 3) def test_badfuture5(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future5 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future5", 4) def test_badfuture6(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future6 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future6", 3) def test_badfuture7(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future7 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future7", 3, 53) def test_badfuture8(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future8 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future8", 3) def test_badfuture9(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future9 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future9", 3, 0) def test_badfuture10(self): - try: + with self.assertRaises(SyntaxError) as cm: from test import badsyntax_future10 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future10", '3')) - else: - self.fail("expected exception didn't occur") + self.check_syntax_error(cm.exception, "badsyntax_future10", 3, 0) def test_parserhack(self): # test that the parser.c::future_hack function works as expected |