MCPcopy Index your code
hub / github.com/pyscript/pyscript / test_when_decorates_an_event

Function test_when_decorates_an_event

core/tests/python/tests/test_events.py:482–503  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

480
481
482def 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
506async def test_when_with_list_of_events():

Callers

nothing calls this directly

Calls 2

triggerMethod · 0.95
EventClass · 0.90

Tested by

no test coverage detected