summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2017-10-22 21:41:51 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2017-10-22 21:41:51 (GMT)
commitae3087c6382011c47db82fea4d05f8bbf514265d (patch)
treec5d832a760d9898700f1ca397a5a305734b3d77a /Lib/test/test_exceptions.py
parent91dc64ba3f51100540b2ab6c6cd72c3bb18a6d49 (diff)
downloadcpython-ae3087c6382011c47db82fea4d05f8bbf514265d.zip
cpython-ae3087c6382011c47db82fea4d05f8bbf514265d.tar.gz
cpython-ae3087c6382011c47db82fea4d05f8bbf514265d.tar.bz2
Move exc state to generator. Fixes bpo-25612 (#1773)
Move exception state information from frame objects to coroutine (generator/thread) object where it belongs.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index a25f3bf..ad4bc09 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1097,6 +1097,62 @@ class ExceptionTests(unittest.TestCase):
self.assertIn("test message", report)
self.assertTrue(report.endswith("\n"))
+ def test_yield_in_nested_try_excepts(self):
+ #Issue #25612
+ class MainError(Exception):
+ pass
+
+ class SubError(Exception):
+ pass
+
+ def main():
+ try:
+ raise MainError()
+ except MainError:
+ try:
+ yield
+ except SubError:
+ pass
+ raise
+
+ coro = main()
+ coro.send(None)
+ with self.assertRaises(MainError):
+ coro.throw(SubError())
+
+ def test_generator_doesnt_retain_old_exc2(self):
+ #Issue 28884#msg282532
+ def g():
+ try:
+ raise ValueError
+ except ValueError:
+ yield 1
+ self.assertEqual(sys.exc_info(), (None, None, None))
+ yield 2
+
+ gen = g()
+
+ try:
+ raise IndexError
+ except IndexError:
+ self.assertEqual(next(gen), 1)
+ self.assertEqual(next(gen), 2)
+
+ def test_raise_in_generator(self):
+ #Issue 25612#msg304117
+ def g():
+ yield 1
+ raise
+ yield 2
+
+ with self.assertRaises(ZeroDivisionError):
+ i = g()
+ try:
+ 1/0
+ except:
+ next(i)
+ next(i)
+
class ImportErrorTests(unittest.TestCase):