summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2020-05-17 04:14:48 (GMT)
committerGitHub <noreply@github.com>2020-05-17 04:14:48 (GMT)
commitd7184d3dbd249444ec3961641dc08a9ad3c1ac34 (patch)
tree6e909caf899f7d657e6b0007777bade4e8f8df34
parent2c8cd06afe8e0abb52367f85978f19b88e2df53e (diff)
downloadcpython-d7184d3dbd249444ec3961641dc08a9ad3c1ac34.zip
cpython-d7184d3dbd249444ec3961641dc08a9ad3c1ac34.tar.gz
cpython-d7184d3dbd249444ec3961641dc08a9ad3c1ac34.tar.bz2
bpo-29587: Add another test for the gen.throw() fix. (GH-19859)
-rw-r--r--Lib/test/test_generators.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index 348ae15..87cc2df 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -332,6 +332,28 @@ class GeneratorThrowTest(unittest.TestCase):
context = cm.exception.__context__
self.assertEqual((type(context), context.args), (KeyError, ('a',)))
+ def test_exception_context_with_yield_inside_generator(self):
+ # Check that the context is also available from inside the generator
+ # with yield, as opposed to outside.
+ def f():
+ try:
+ raise KeyError('a')
+ except Exception:
+ try:
+ yield
+ except Exception as exc:
+ self.assertEqual(type(exc), ValueError)
+ context = exc.__context__
+ self.assertEqual((type(context), context.args),
+ (KeyError, ('a',)))
+ yield 'b'
+
+ gen = f()
+ gen.send(None)
+ actual = gen.throw(ValueError)
+ # This ensures that the assertions inside were executed.
+ self.assertEqual(actual, 'b')
+
def test_exception_context_with_yield_from(self):
def f():
yield