When the @when decorator is used on a function to handle an Event instance, the function should be called when the Event object is triggered.
()
| 480 | |
| 481 | |
| 482 | def test_when_decorates_an_event(): |
| 483 | """ |
| 484 | When the @when decorator is used on a function to handle an Event |
| 485 | instance, the function should be called when the Event object is |
| 486 | triggered. |
| 487 | """ |
| 488 | whenable = Event() |
| 489 | counter = 0 |
| 490 | |
| 491 | @when(whenable) |
| 492 | def handler(result): |
| 493 | """ |
| 494 | A function that should be called when the whenable object is |
| 495 | triggered. |
| 496 | """ |
| 497 | nonlocal counter |
| 498 | counter += 1 |
| 499 | assert result == "ok" |
| 500 | |
| 501 | assert counter == 0 |
| 502 | whenable.trigger("ok") |
| 503 | assert counter == 1 |
| 504 | |
| 505 | |
| 506 | async def test_when_with_list_of_events(): |