MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_except_gen_except

Method test_except_gen_except

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected