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

Method test_register_decorator

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

Source from the content-addressed store, hash-verified

2305 self.assertEqual(g(D()), "B")
2306
2307 def test_register_decorator(self):
2308 @functools.singledispatch
2309 def g(obj):
2310 return "base"
2311 @g.register(int)
2312 def g_int(i):
2313 return "int %s" % (i,)
2314 self.assertEqual(g(""), "base")
2315 self.assertEqual(g(12), "int 12")
2316 self.assertIs(g.dispatch(int), g_int)
2317 self.assertIs(g.dispatch(object), g.dispatch(str))
2318 # Note: in the assert above this is not g.
2319 # @singledispatch returns the wrapper.
2320
2321 def test_wrapping_attributes(self):
2322 @functools.singledispatch

Callers

nothing calls this directly

Calls 4

gFunction · 0.70
assertEqualMethod · 0.45
assertIsMethod · 0.45
dispatchMethod · 0.45

Tested by

no test coverage detected