| 12 | |
| 13 | |
| 14 | def test_callbacks(): |
| 15 | from functools import partial |
| 16 | |
| 17 | def func1(): |
| 18 | return "func1" |
| 19 | |
| 20 | def func2(a, b, c, d): |
| 21 | return "func2", a, b, c, d |
| 22 | |
| 23 | def func3(a): |
| 24 | return f"func3({a})" |
| 25 | |
| 26 | assert m.test_callback1(func1) == "func1" |
| 27 | assert m.test_callback2(func2) == ("func2", "Hello", "x", True, 5) |
| 28 | assert m.test_callback1(partial(func2, 1, 2, 3, 4)) == ("func2", 1, 2, 3, 4) |
| 29 | assert m.test_callback1(partial(func3, "partial")) == "func3(partial)" |
| 30 | assert m.test_callback3(lambda i: i + 1) == "func(43) = 44" |
| 31 | |
| 32 | f = m.test_callback4() |
| 33 | assert f(43) == 44 |
| 34 | f = m.test_callback5() |
| 35 | assert f(number=43) == 44 |
| 36 | |
| 37 | |
| 38 | def test_bound_method_callback(): |