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

Method test_meth_class_get

Lib/test/test_descr.py:4596–4637  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4594
4595 @support.impl_detail("testing an internal kind of method object")
4596 def test_meth_class_get(self):
4597 # Testing __get__ method of METH_CLASS C methods...
4598 # Full coverage of descrobject.c::classmethod_get()
4599
4600 # Baseline
4601 arg = [1, 2, 3]
4602 res = {1: None, 2: None, 3: None}
4603 self.assertEqual(dict.fromkeys(arg), res)
4604 self.assertEqual({}.fromkeys(arg), res)
4605
4606 # Now get the descriptor
4607 descr = dict.__dict__["fromkeys"]
4608
4609 # More baseline using the descriptor directly
4610 self.assertEqual(descr.__get__(None, dict)(arg), res)
4611 self.assertEqual(descr.__get__({})(arg), res)
4612
4613 # Now check various error cases
4614 try:
4615 descr.__get__(None, None)
4616 except TypeError:
4617 pass
4618 else:
4619 self.fail("shouldn't have allowed descr.__get__(None, None)")
4620 try:
4621 descr.__get__(42)
4622 except TypeError:
4623 pass
4624 else:
4625 self.fail("shouldn't have allowed descr.__get__(42)")
4626 try:
4627 descr.__get__(None, 42)
4628 except TypeError:
4629 pass
4630 else:
4631 self.fail("shouldn't have allowed descr.__get__(None, 42)")
4632 try:
4633 descr.__get__(None, int)
4634 except TypeError:
4635 pass
4636 else:
4637 self.fail("shouldn't have allowed descr.__get__(None, int)")
4638
4639 def test_isinst_isclass(self):
4640 # Testing proxy isinstance() and isclass()...

Callers

nothing calls this directly

Calls 4

assertEqualMethod · 0.45
fromkeysMethod · 0.45
__get__Method · 0.45
failMethod · 0.45

Tested by

no test coverage detected