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

Method test_async_push

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

Source from the content-addressed store, hash-verified

585
586 @_async_test
587 async def test_async_push(self):
588 exc_raised = ZeroDivisionError
589 async def _expect_exc(exc_type, exc, exc_tb):
590 self.assertIs(exc_type, exc_raised)
591 async def _suppress_exc(*exc_details):
592 return True
593 async def _expect_ok(exc_type, exc, exc_tb):
594 self.assertIsNone(exc_type)
595 self.assertIsNone(exc)
596 self.assertIsNone(exc_tb)
597 class ExitCM(object):
598 def __init__(self, check_exc):
599 self.check_exc = check_exc
600 async def __aenter__(self):
601 self.fail("Should not be called!")
602 async def __aexit__(self, *exc_details):
603 await self.check_exc(*exc_details)
604
605 async with self.exit_stack() as stack:
606 stack.push_async_exit(_expect_ok)
607 self.assertIs(stack._exit_callbacks[-1][1], _expect_ok)
608 cm = ExitCM(_expect_ok)
609 stack.push_async_exit(cm)
610 self.assertIs(stack._exit_callbacks[-1][1].__self__, cm)
611 stack.push_async_exit(_suppress_exc)
612 self.assertIs(stack._exit_callbacks[-1][1], _suppress_exc)
613 cm = ExitCM(_expect_exc)
614 stack.push_async_exit(cm)
615 self.assertIs(stack._exit_callbacks[-1][1].__self__, cm)
616 stack.push_async_exit(_expect_exc)
617 self.assertIs(stack._exit_callbacks[-1][1], _expect_exc)
618 stack.push_async_exit(_expect_exc)
619 self.assertIs(stack._exit_callbacks[-1][1], _expect_exc)
620 1/0
621
622 @_async_test
623 async def test_enter_async_context(self):

Callers

nothing calls this directly

Calls 3

push_async_exitMethod · 0.80
ExitCMClass · 0.70
assertIsMethod · 0.45

Tested by

no test coverage detected