mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
bpo-29587: Add another test for the gen.throw() fix. (GH-19859)
This commit is contained in:
parent
2c8cd06afe
commit
d7184d3dbd
1 changed files with 22 additions and 0 deletions
|
|
@ -332,6 +332,28 @@ class GeneratorThrowTest(unittest.TestCase):
|
||||||
context = cm.exception.__context__
|
context = cm.exception.__context__
|
||||||
self.assertEqual((type(context), context.args), (KeyError, ('a',)))
|
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 test_exception_context_with_yield_from(self):
|
||||||
def f():
|
def f():
|
||||||
yield
|
yield
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue