예제 #1
0
def test_on_does_not_emits_error_when_not_listening_for_errors(
        ees: EventEmitterS, error_helper: "EEExceptionHelper") -> None:
    ees.on("event", error_helper.error_raiser)
    assert ees.listener_count("event") == 1
    assert ees.listener_count("error") == 0
    assert ees.emit("event", 1, data=2)
    error_helper.assert_error_was_not_emitted()
예제 #2
0
def test_get_event_names(ees: EventEmitterS,
                         arg_swallower: Callable[..., None]) -> None:
    events = {"event", "event1", "event2", "event3"}
    for event in events:
        ees.on(event, arg_swallower)
    assert all(registered_event_name in events
               for registered_event_name in ees.event_names())
예제 #3
0
def test_on_decorator(ees: EventEmitterS, mock: Mock) -> None:
    @ees.on("event")
    def handler(*args, **kwargs) -> None:
        mock.method(*args, **kwargs)

    assert ees.listener_count("event") == 1
    assert handler is ees.listeners("event")[0]
    assert ees.emit("event", 1, data=2)
    mock.method.assert_called_with(1, data=2)
    assert ees.listener_count("event") == 1
    assert handler is ees.listeners("event")[0]
예제 #4
0
async def test_coroutine_listener_does_not_emits_error_when_not_listening_for_errors(
    ees_with_event_loop: EventEmitterS,
    error_helper: "EEExceptionHelper",
    event_loop: AbstractEventLoop,
) -> None:
    error_helper.with_deferred(event_loop)
    ees_with_event_loop.on("event", error_helper.error_raiser_async)
    assert ees_with_event_loop.listener_count("event") == 1
    assert ees_with_event_loop.listener_count("error") == 0
    assert ees_with_event_loop.emit("event", 1, data=2)
    await error_helper.assert_error_was_not_emitted_async()
예제 #5
0
def test_once_decorator_does_not_emits_error_when_not_listening_for_errors(
        ees: EventEmitterS, error_helper: "EEExceptionHelper") -> None:
    @ees.once("event")
    def handler(*args, **kwargs) -> None:
        error_helper.error_raiser(*args, **kwargs)

    assert ees.listener_count("event") == 1
    assert ees.listener_count("error") == 0
    assert ees.emit("event", 1, data=2)
    error_helper.assert_error_was_not_emitted()
    assert ees.listener_count("event") == 0
    assert ees.listener_count("error") == 0
예제 #6
0
async def test_coroutine_listener_decorator(ees_with_event_loop: EventEmitterS,
                                            mock: Mock,
                                            deferred: Future) -> None:
    @ees_with_event_loop.on("event")
    async def handler(*args, **kwargs) -> None:
        mock.method(*args, **kwargs)
        deferred.set_result(True)

    assert ees_with_event_loop.listener_count("event") == 1
    assert handler is ees_with_event_loop.listeners("event")[0]
    assert ees_with_event_loop.emit("event", 1, data=2)
    assert await deferred
    mock.method.assert_called_with(1, data=2)
    assert ees_with_event_loop.listener_count("event") == 1
    assert handler is ees_with_event_loop.listeners("event")[0]
예제 #7
0
def test_once(ees: EventEmitterS, mock: Mock) -> None:
    ees.once("event", mock.method)

    assert ees.listener_count("event") == 1
    assert mock.method is ees.listeners("event")[0]
    assert ees.emit("event", 1, data=2)
    assert not ees.emit("event", 1, data=2)
    mock.method.assert_called_once_with(1, data=2)
    assert ees.listener_count("event") == 0
    assert mock.method not in ees.listeners("event")
예제 #8
0
def test_remove_all_listeners(ees: EventEmitterS,
                              arg_swallower: Callable[..., None]) -> None:
    ees.on("event", arg_swallower)
    assert ees.listener_count("event") == 1
    assert arg_swallower is ees.listeners("event")[0]
    ees.remove_all_listeners()
    assert ees.listener_count("event") == 0
예제 #9
0
파일: conftest.py 프로젝트: N0taN3rd/pyee2
def ees_with_event_loop(event_loop: AbstractEventLoop) -> EventEmitterS:
    return EventEmitterS(loop=event_loop)
예제 #10
0
파일: conftest.py 프로젝트: N0taN3rd/pyee2
def ees() -> EventEmitterS:
    return EventEmitterS()
예제 #11
0
def test_get_listeners_registered_for_event(
        ees: EventEmitterS, arg_swallower: Callable[..., None]) -> None:
    ees.on("event", arg_swallower)
    ees_listeners = ees.listeners("event")
    assert len(ees_listeners) == 1
    assert ees_listeners[0] is arg_swallower