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

Method test_except_gen_except

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

Source from the content-addressed store, hash-verified

459 self.assertIsNone(sys.exception())
460
461 def test_except_gen_except(self):
462 def gen():
463 try:
464 self.assertIsNone(sys.exception())
465 yield
466 # we are called from "except ValueError:", TypeError must
467 # inherit ValueError in its context
468 raise TypeError()
469 except TypeError as exc:
470 self.assertIsInstance(sys.exception(), TypeError)
471 self.assertEqual(type(exc.__context__), ValueError)
472 # here we are still called from the "except ValueError:"
473 self.assertIsInstance(sys.exception(), ValueError)
474 yield
475 self.assertIsNone(sys.exception())
476 yield "done"
477
478 g = gen()
479 next(g)
480 try:
481 raise ValueError
482 except Exception:
483 next(g)
484
485 self.assertEqual(next(g), "done")
486 self.assertIsNone(sys.exception())
487
488 def test_nested_gen_except_loop(self):
489 def gen():

Callers

nothing calls this directly

Calls 4

assertIsNoneMethod · 0.80
genFunction · 0.70
assertEqualMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected