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

Method test_classmethod_register

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

Source from the content-addressed store, hash-verified

2909 a2.t.foo
2910
2911 def test_classmethod_register(self):
2912 class A:
2913 def __init__(self, arg):
2914 self.arg = arg
2915
2916 @functools.singledispatchmethod
2917 @classmethod
2918 def t(cls, arg):
2919 return cls("base")
2920 @t.register(int)
2921 @classmethod
2922 def _(cls, arg):
2923 return cls("int")
2924 @t.register(str)
2925 @classmethod
2926 def _(cls, arg):
2927 return cls("str")
2928
2929 self.assertEqual(A.t(0).arg, "int")
2930 self.assertEqual(A.t('').arg, "str")
2931 self.assertEqual(A.t(0.0).arg, "base")
2932
2933 def test_callable_register(self):
2934 class A:

Callers

nothing calls this directly

Calls 2

assertEqualMethod · 0.45
tMethod · 0.45

Tested by

no test coverage detected