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

Method test_attrgetter

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

Source from the content-addressed store, hash-verified

678 return pickle.loads(pickled)
679
680 def test_attrgetter(self):
681 attrgetter = self.module.attrgetter
682 class A:
683 pass
684 a = A()
685 a.x = 'X'
686 a.y = 'Y'
687 a.z = 'Z'
688 a.t = A()
689 a.t.u = A()
690 a.t.u.v = 'V'
691 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
692 with self.subTest(proto=proto):
693 f = attrgetter('x')
694 f2 = self.copy(f, proto)
695 self.assertEqual(repr(f2), repr(f))
696 self.assertEqual(f2(a), f(a))
697 # multiple gets
698 f = attrgetter('x', 'y', 'z')
699 f2 = self.copy(f, proto)
700 self.assertEqual(repr(f2), repr(f))
701 self.assertEqual(f2(a), f(a))
702 # recursive gets
703 f = attrgetter('t.u.v')
704 f2 = self.copy(f, proto)
705 self.assertEqual(repr(f2), repr(f))
706 self.assertEqual(f2(a), f(a))
707
708 def test_itemgetter(self):
709 itemgetter = self.module.itemgetter

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected