FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-29587: Add another test for the gen.throw() exception chain fix by cjerdonek · Pull Request #19859 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 22 additions & 0 deletions Lib/test/test_generators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,28 @@ def f():
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
Expand Down

Back | FazBrowse Home | New Git URL