MCPcopy Create free account
hub / github.com/RustPython/RustPython / test_except_throw

Method test_except_throw

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

nextFunction · 0.85
assertIsNoneMethod · 0.80
throwMethod · 0.45
assertRaisesMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected