aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index e752ab72ccf..864422390ad 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1488,5 +1488,88 @@ class ImportErrorTests(unittest.TestCase):
self.assertEqual(exc.path, orig.path)
+class PEP626Tests(unittest.TestCase):
+
+ def lineno_after_raise(self, f, line):
+ try:
+ f()
+ except Exception as ex:
+ t = ex.__traceback__
+ while t.tb_next:
+ t = t.tb_next
+ frame = t.tb_frame
+ self.assertEqual(frame.f_lineno-frame.f_code.co_firstlineno, line)
+
+ def test_lineno_after_raise_simple(self):
+ def simple():
+ 1/0
+ pass
+ self.lineno_after_raise(simple, 1)
+
+ def test_lineno_after_raise_in_except(self):
+ def in_except():
+ try:
+ 1/0
+ except:
+ 1/0
+ pass
+ self.lineno_after_raise(in_except, 4)
+
+ def test_lineno_after_other_except(self):
+ def other_except():
+ try:
+ 1/0
+ except TypeError as ex:
+ pass
+ self.lineno_after_raise(other_except, 3)
+
+ def test_lineno_in_named_except(self):
+ def in_named_except():
+ try:
+ 1/0
+ except Exception as ex:
+ 1/0
+ pass
+ self.lineno_after_raise(in_named_except, 4)
+
+ def test_lineno_in_try(self):
+ def in_try():
+ try:
+ 1/0
+ finally:
+ pass
+ self.lineno_after_raise(in_try, 4)
+
+ def test_lineno_in_finally_normal(self):
+ def in_finally_normal():
+ try:
+ pass
+ finally:
+ 1/0
+ pass
+ self.lineno_after_raise(in_finally_normal, 4)
+
+ def test_lineno_in_finally_except(self):
+ def in_finally_except():
+ try:
+ 1/0
+ finally:
+ 1/0
+ pass
+ self.lineno_after_raise(in_finally_except, 4)
+
+ def test_lineno_after_with(self):
+ class Noop:
+ def __enter__(self):
+ return self
+ def __exit__(self, *args):
+ pass
+ def after_with():
+ with Noop():
+ 1/0
+ pass
+ self.lineno_after_raise(after_with, 2)
+
+
if __name__ == '__main__':
unittest.main()