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

Method test_callable_register

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

Source from the content-addressed store, hash-verified

2931 self.assertEqual(A.t(0.0).arg, "base")
2932
2933 def test_callable_register(self):
2934 class A:
2935 def __init__(self, arg):
2936 self.arg = arg
2937
2938 @functools.singledispatchmethod
2939 @classmethod
2940 def t(cls, arg):
2941 return cls("base")
2942
2943 @A.t.register(int)
2944 @classmethod
2945 def _(cls, arg):
2946 return cls("int")
2947 @A.t.register(str)
2948 @classmethod
2949 def _(cls, arg):
2950 return cls("str")
2951
2952 self.assertEqual(A.t(0).arg, "int")
2953 self.assertEqual(A.t('').arg, "str")
2954 self.assertEqual(A.t(0.0).arg, "base")
2955
2956 def test_abstractmethod_register(self):
2957 class Abstract(metaclass=abc.ABCMeta):

Callers

nothing calls this directly

Calls 2

assertEqualMethod · 0.45
tMethod · 0.45

Tested by

no test coverage detected