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

Method test_callable_register

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

Source from the content-addressed store, hash-verified

2891 self.assertEqual(A.t(0.0).arg, "base")
2892
2893 def test_callable_register(self):
2894 class A:
2895 def __init__(self, arg):
2896 self.arg = arg
2897
2898 @functools.singledispatchmethod
2899 @classmethod
2900 def t(cls, arg):
2901 return cls("base")
2902
2903 @A.t.register(int)
2904 @classmethod
2905 def _(cls, arg):
2906 return cls("int")
2907 @A.t.register(str)
2908 @classmethod
2909 def _(cls, arg):
2910 return cls("str")
2911
2912 self.assertEqual(A.t(0).arg, "int")
2913 self.assertEqual(A.t('').arg, "str")
2914 self.assertEqual(A.t(0.0).arg, "base")
2915
2916 def test_abstractmethod_register(self):
2917 class Abstract(metaclass=abc.ABCMeta):

Callers

nothing calls this directly

Calls 2

assertEqualMethod · 0.45
tMethod · 0.45

Tested by

no test coverage detected