Example #1
0
def test_subscribe_no_app():

    dispatcher = EventDispatcher()

    with pytest.raises(ImproperlyConfigured) as exc_info:
        dispatcher.subscribe("invalid type")(lambda _: _)  # noqa

    assert str(exc_info.value) == "Event dispatcher is not initialized."
Example #2
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
Example #3
0
def test_subscribe_invalid_type(dispatcher: EventDispatcher):

    with pytest.raises(TypeError):
        dispatcher.subscribe("invalid type")(lambda _: _)  # noqa