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

Method test_except_throw

Lib/test/test_generators.py:413–447  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

411 # is correctly saved/restored in PyEval_EvalFrameEx().
412
413 def test_except_throw(self):
414 def store_raise_exc_generator():
415 try:
416 self.assertIsNone(sys.exception())
417 yield
418 except Exception as exc:
419 # exception raised by gen.throw(exc)
420 self.assertIsInstance(sys.exception(), ValueError)
421 self.assertIsNone(exc.__context__)
422 yield
423
424 # ensure that the exception is not lost
425 self.assertIsInstance(sys.exception(), ValueError)
426 yield
427
428 # we should be able to raise back the ValueError
429 raise
430
431 make = store_raise_exc_generator()
432 next(make)
433
434 try:
435 raise ValueError()
436 except Exception as exc:
437 try:
438 make.throw(exc)
439 except Exception:
440 pass
441
442 next(make)
443 with self.assertRaises(ValueError) as cm:
444 next(make)
445 self.assertIsNone(cm.exception.__context__)
446
447 self.assertIsNone(sys.exception())
448
449 def test_except_next(self):
450 def gen():

Callers

nothing calls this directly

Calls 4

assertIsNoneMethod · 0.80
throwMethod · 0.45
assertRaisesMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected