def test_c_classes(self): @singledispatch def g(obj): return "base" @g.register(decimal.DecimalException) def _(obj): return obj.args subn = decimal.Subnormal("Exponent < Emin") rnd = decimal.Rounded("Number got rounded") self.assertEqual(g(subn), ("Exponent < Emin",)) self.assertEqual(g(rnd), ("Number got rounded",)) @g.register(decimal.Subnormal) def _g(obj): return "Too small to care." self.assertEqual(g(subn), "Too small to care.") self.assertEqual(g(rnd), ("Number got rounded",))
def test_c_classes(): @allot def g(obj): return "base" @g.register(decimal.DecimalException) def _(obj): return obj.args subn = decimal.Subnormal("Exponent < Emin") rnd = decimal.Rounded("Number got rounded") assert g(subn) == ("Exponent < Emin", ) assert g(rnd) == ("Number got rounded", ) @g.register(decimal.Subnormal) def _(obj): return "Too small to care." assert g(subn) == "Too small to care." assert g(rnd) == ("Number got rounded", )