Exemplo n.º 1
0
def test_event_subscribe_and_dispatch(dispatcher: EventDispatcher):

    event_dispatched = DummyEvent()
    event_subscribed = None

    def handler(event: DummyEvent):
        nonlocal event_subscribed
        event_subscribed = event

    dispatcher.subscribe(DummyEvent, handler)
    dispatcher.dispatch(event_dispatched)

    assert event_subscribed == event_dispatched
Exemplo n.º 2
0
def test_dispatch_invalid_type(dispatcher: EventDispatcher):

    with pytest.raises(TypeError):
        dispatcher.dispatch("invalid type")  # noqa