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

Method test_callback

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

Source from the content-addressed store, hash-verified

695 pass
696
697 def test_callback(self):
698 expected = [
699 ((), {}),
700 ((1,), {}),
701 ((1,2), {}),
702 ((), dict(example=1)),
703 ((1,), dict(example=1)),
704 ((1,2), dict(example=1)),
705 ((1,2), dict(self=3, callback=4)),
706 ]
707 result = []
708 def _exit(*args, **kwds):
709 """Test metadata propagation"""
710 result.append((args, kwds))
711 with self.exit_stack() as stack:
712 for args, kwds in reversed(expected):
713 if args and kwds:
714 f = stack.callback(_exit, *args, **kwds)
715 elif args:
716 f = stack.callback(_exit, *args)
717 elif kwds:
718 f = stack.callback(_exit, **kwds)
719 else:
720 f = stack.callback(_exit)
721 self.assertIs(f, _exit)
722 for wrapper in stack._exit_callbacks:
723 self.assertIs(wrapper[1].__wrapped__, _exit)
724 self.assertNotEqual(wrapper[1].__name__, _exit.__name__)
725 self.assertIsNone(wrapper[1].__doc__, _exit.__doc__)
726 self.assertEqual(result, expected)
727
728 result = []
729 with self.exit_stack() as stack:
730 with self.assertRaises(TypeError):
731 stack.callback(arg=1)
732 with self.assertRaises(TypeError):
733 self.exit_stack.callback(arg=2)
734 with self.assertRaises(TypeError):
735 stack.callback(callback=_exit, arg=3)
736 self.assertEqual(result, [])
737
738 def test_push(self):
739 exc_raised = ZeroDivisionError

Callers

nothing calls this directly

Calls 6

assertNotEqualMethod · 0.80
assertIsNoneMethod · 0.80
callbackMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected