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

Method test_enter_context

Lib/test/test_contextlib.py:772–789  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

770 1/0
771
772 def test_enter_context(self):
773 class TestCM(object):
774 def __enter__(self):
775 result.append(1)
776 def __exit__(self, *exc_details):
777 result.append(3)
778
779 result = []
780 cm = TestCM()
781 with self.exit_stack() as stack:
782 @stack.callback # Registered first => cleaned up last
783 def _exit():
784 result.append(4)
785 self.assertIsNotNone(_exit)
786 stack.enter_context(cm)
787 self.assertIs(stack._exit_callbacks[-1][1].__self__, cm)
788 result.append(2)
789 self.assertEqual(result, [1, 2, 3, 4])
790
791 def test_enter_context_classmethod(self):
792 class TestCM:

Callers

nothing calls this directly

Calls 6

assertIsNotNoneMethod · 0.80
enter_contextMethod · 0.80
TestCMClass · 0.70
assertIsMethod · 0.45
appendMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected