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

Method test_methodcaller

Lib/test/test_operator.py:723–752  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

721 self.assertEqual(f2(a), f(a))
722
723 def test_methodcaller(self):
724 methodcaller = self.module.methodcaller
725 class A:
726 def foo(self, *args, **kwds):
727 return args[0] + args[1]
728 def bar(self, f=42):
729 return f
730 def baz(*args, **kwds):
731 return kwds['name'], kwds['self']
732 a = A()
733 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
734 with self.subTest(proto=proto):
735 f = methodcaller('bar')
736 f2 = self.copy(f, proto)
737 self.assertEqual(repr(f2), repr(f))
738 self.assertEqual(f2(a), f(a))
739 # positional args
740 f = methodcaller('foo', 1, 2)
741 f2 = self.copy(f, proto)
742 self.assertEqual(repr(f2), repr(f))
743 self.assertEqual(f2(a), f(a))
744 # keyword args
745 f = methodcaller('bar', f=5)
746 f2 = self.copy(f, proto)
747 self.assertEqual(repr(f2), repr(f))
748 self.assertEqual(f2(a), f(a))
749 f = methodcaller('baz', self='eggs', name='spam')
750 f2 = self.copy(f, proto)
751 # Can't test repr consistently with multiple keyword args
752 self.assertEqual(f2(a), f(a))
753
754class PyPyOperatorPickleTestCase(OperatorPickleTestCase, unittest.TestCase):
755 module = py_operator

Callers

nothing calls this directly

Calls 7

copyMethod · 0.95
methodcallerClass · 0.85
f2Function · 0.85
AClass · 0.70
fFunction · 0.70
subTestMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected