MCPcopy Index your code
hub / github.com/python/cpython / test_delegating_throw

Method test_delegating_throw

Lib/test/test_yield_from.py:301–339  ·  view source on GitHub ↗

Test delegating 'throw'

(self)

Source from the content-addressed store, hash-verified

299 ])
300
301 def test_delegating_throw(self):
302 """
303 Test delegating 'throw'
304 """
305 trace = []
306 def g1():
307 try:
308 trace.append("Starting g1")
309 yield "g1 ham"
310 yield from g2()
311 yield "g1 eggs"
312 finally:
313 trace.append("Finishing g1")
314 def g2():
315 try:
316 trace.append("Starting g2")
317 yield "g2 spam"
318 yield "g2 more spam"
319 finally:
320 trace.append("Finishing g2")
321 try:
322 g = g1()
323 for i in range(2):
324 x = next(g)
325 trace.append("Yielded %s" % (x,))
326 e = ValueError("tomato ejected")
327 g.throw(e)
328 except ValueError as e:
329 self.assertEqual(e.args[0], "tomato ejected")
330 else:
331 self.fail("subgenerator failed to raise ValueError")
332 self.assertEqual(trace,[
333 "Starting g1",
334 "Yielded g1 ham",
335 "Starting g2",
336 "Yielded g2 spam",
337 "Finishing g2",
338 "Finishing g1",
339 ])
340
341 def test_value_attribute_of_StopIteration_exception(self):
342 """

Callers

nothing calls this directly

Calls 5

g1Function · 0.85
appendMethod · 0.45
throwMethod · 0.45
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected