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

Method test_method_register

Lib/test/test_functools.py:2795–2819  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2793 self.assertEqual(i("str"), "str")
2794
2795 def test_method_register(self):
2796 class A:
2797 @functools.singledispatchmethod
2798 def t(self, arg):
2799 self.arg = "base"
2800 @t.register(int)
2801 def _(self, arg):
2802 self.arg = "int"
2803 @t.register(str)
2804 def _(self, arg):
2805 self.arg = "str"
2806 a = A()
2807
2808 a.t(0)
2809 self.assertEqual(a.arg, "int")
2810 aa = A()
2811 self.assertNotHasAttr(aa, 'arg')
2812 a.t('')
2813 self.assertEqual(a.arg, "str")
2814 aa = A()
2815 self.assertNotHasAttr(aa, 'arg')
2816 a.t(0.0)
2817 self.assertEqual(a.arg, "base")
2818 aa = A()
2819 self.assertNotHasAttr(aa, 'arg')
2820
2821 def test_staticmethod_register(self):
2822 class A:

Callers

nothing calls this directly

Calls 4

tMethod · 0.95
assertNotHasAttrMethod · 0.80
AClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected