MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_method_register

Method test_method_register

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

Source from the content-addressed store, hash-verified

2755 self.assertEqual(i("str"), "str")
2756
2757 def test_method_register(self):
2758 class A:
2759 @functools.singledispatchmethod
2760 def t(self, arg):
2761 self.arg = "base"
2762 @t.register(int)
2763 def _(self, arg):
2764 self.arg = "int"
2765 @t.register(str)
2766 def _(self, arg):
2767 self.arg = "str"
2768 a = A()
2769
2770 a.t(0)
2771 self.assertEqual(a.arg, "int")
2772 aa = A()
2773 self.assertNotHasAttr(aa, 'arg')
2774 a.t('')
2775 self.assertEqual(a.arg, "str")
2776 aa = A()
2777 self.assertNotHasAttr(aa, 'arg')
2778 a.t(0.0)
2779 self.assertEqual(a.arg, "base")
2780 aa = A()
2781 self.assertNotHasAttr(aa, 'arg')
2782
2783 def test_staticmethod_register(self):
2784 class A:

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected