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

Method test_field_descriptor

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

Source from the content-addressed store, hash-verified

678
679 @support.cpython_only
680 def test_field_descriptor(self):
681 Point = namedtuple('Point', 'x y')
682 p = Point(11, 22)
683 self.assertTrue(inspect.isdatadescriptor(Point.x))
684 self.assertEqual(Point.x.__get__(p), 11)
685 self.assertRaises(AttributeError, Point.x.__set__, p, 33)
686 self.assertRaises(AttributeError, Point.x.__delete__, p)
687
688 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
689 with self.subTest(proto=proto):
690 class NewPoint(tuple):
691 x = pickle.loads(pickle.dumps(Point.x, proto))
692 y = pickle.loads(pickle.dumps(Point.y, proto))
693
694 np = NewPoint([1, 2])
695
696 self.assertEqual(np.x, 1)
697 self.assertEqual(np.y, 2)
698
699 def test_new_builtins_issue_43102(self):
700 obj = namedtuple('C', ())

Callers

nothing calls this directly

Calls 8

namedtupleFunction · 0.90
NewPointClass · 0.85
assertTrueMethod · 0.80
PointClass · 0.70
assertEqualMethod · 0.45
__get__Method · 0.45
assertRaisesMethod · 0.45
subTestMethod · 0.45

Tested by

no test coverage detected