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

Method test_async_push

Lib/test/test_contextlib_async.py:577–610  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

575 self.assertEqual(result, [])
576
577 async def test_async_push(self):
578 exc_raised = ZeroDivisionError
579 async def _expect_exc(exc_type, exc, exc_tb):
580 self.assertIs(exc_type, exc_raised)
581 async def _suppress_exc(*exc_details):
582 return True
583 async def _expect_ok(exc_type, exc, exc_tb):
584 self.assertIsNone(exc_type)
585 self.assertIsNone(exc)
586 self.assertIsNone(exc_tb)
587 class ExitCM(object):
588 def __init__(self, check_exc):
589 self.check_exc = check_exc
590 async def __aenter__(self):
591 self.fail("Should not be called!")
592 async def __aexit__(self, *exc_details):
593 await self.check_exc(*exc_details)
594
595 async with self.exit_stack() as stack:
596 stack.push_async_exit(_expect_ok)
597 self.assertIs(stack._exit_callbacks[-1][1], _expect_ok)
598 cm = ExitCM(_expect_ok)
599 stack.push_async_exit(cm)
600 self.assertIs(stack._exit_callbacks[-1][1].__self__, cm)
601 stack.push_async_exit(_suppress_exc)
602 self.assertIs(stack._exit_callbacks[-1][1], _suppress_exc)
603 cm = ExitCM(_expect_exc)
604 stack.push_async_exit(cm)
605 self.assertIs(stack._exit_callbacks[-1][1].__self__, cm)
606 stack.push_async_exit(_expect_exc)
607 self.assertIs(stack._exit_callbacks[-1][1], _expect_exc)
608 stack.push_async_exit(_expect_exc)
609 self.assertIs(stack._exit_callbacks[-1][1], _expect_exc)
610 1/0
611
612 async def test_enter_async_context(self):
613 class TestCM(object):

Callers

nothing calls this directly

Calls 3

push_async_exitMethod · 0.80
ExitCMClass · 0.70
assertIsMethod · 0.45

Tested by

no test coverage detected