| 191 | |
| 192 | |
| 193 | def test_dispatch_lazy(): |
| 194 | # this tests the recursive component of dispatch |
| 195 | foo = Dispatch() |
| 196 | foo.register(int, lambda a: a) |
| 197 | |
| 198 | import decimal |
| 199 | |
| 200 | # keep it outside lazy dec for test |
| 201 | def foo_dec(a): |
| 202 | return a + 1 |
| 203 | |
| 204 | @foo.register_lazy("decimal") |
| 205 | def register_decimal(): |
| 206 | import decimal |
| 207 | |
| 208 | foo.register(decimal.Decimal, foo_dec) |
| 209 | |
| 210 | # This test needs to be *before* any other calls |
| 211 | assert foo.dispatch(decimal.Decimal) == foo_dec |
| 212 | assert foo(decimal.Decimal(1)) == decimal.Decimal(2) |
| 213 | assert foo(1) == 1 |
| 214 | |
| 215 | |
| 216 | def test_dispatch_lazy_walks_mro(): |