Esempio n. 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."
Esempio n. 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
Esempio n. 3
0
def test_unsubscribe_invalid_type(dispatcher: EventDispatcher):

    with pytest.raises(TypeError):
        dispatcher.unsubscribe("invalid type", lambda _: _)  # noqa
Esempio n. 4
0
def test_dispatch_invalid_type(dispatcher: EventDispatcher):

    with pytest.raises(TypeError):
        dispatcher.dispatch("invalid type")  # noqa
Esempio n. 5
0
def dispatcher(dummy_app: Flask):
    return EventDispatcher(app=dummy_app)