Ejemplo n.º 1
0
 def test_close_for_inactive_stream(self, mock_app):
     stream = event_manager_base.EventStream(mock_app,
                                             base_events.Event,
                                             timeout=None,
                                             limit=None)
     stream.close()
     mock_app.event_manager.unsubscribe.assert_not_called()
Ejemplo n.º 2
0
    async def test___anext___when_stream_closed(self):
        streamer = event_manager_base.EventStream(mock.Mock(),
                                                  event_type=base_events.Event,
                                                  timeout=float("inf"))

        # flake8 gets annoyed if we use "with" here so here's a hacky alternative
        with pytest.raises(TypeError):
            await streamer.__anext__()
Ejemplo n.º 3
0
    async def test___anext___times_out(self):
        streamer = event_manager_base.EventStream(
            mock.Mock(),
            event_type=base_events.Event,
            timeout=hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME)

        with streamer:
            with pytest.raises(LookupError):
                await streamer.next()
Ejemplo n.º 4
0
    async def test__listener_when_filter_returns_false(self, mock_app):
        stream = event_manager_base.EventStream(mock_app,
                                                base_events.Event,
                                                timeout=None)
        stream.filter(lambda _: False)
        mock_event = object()

        assert await stream._listener(mock_event) is None
        assert not stream._queue
Ejemplo n.º 5
0
    async def test___anext__(self):
        mock_event = object()
        streamer = event_manager_base.EventStream(
            event_manager=mock.Mock(),
            event_type=base_events.Event,
            timeout=hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME,
        )
        streamer._queue.append(mock_event)

        with streamer:
            assert await streamer.next() is mock_event
Ejemplo n.º 6
0
    async def test___anext___waits_for_next_event(self):
        mock_event = object()
        streamer = event_manager_base.EventStream(
            mock.Mock(),
            event_type=base_events.Event,
            timeout=hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 3)

        async def add_event():
            await asyncio.sleep(hikari_test_helpers.REASONABLE_SLEEP_TIME)
            await streamer._listener(mock_event)

        asyncio.create_task(add_event())

        with streamer:
            assert await streamer.next() is mock_event
Ejemplo n.º 7
0
    async def test__listener_when_filter_passes_and_queue_full(self, mock_app):
        stream = event_manager_base.EventStream(mock_app,
                                                base_events.Event,
                                                timeout=None,
                                                limit=2)
        stream._queue.append(object())
        stream._queue.append(object())
        stream.filter(lambda _: True)
        mock_event = object()

        with stream:
            assert await stream._listener(mock_event) is None
            assert await stream.next() is not mock_event
            assert await stream.next() is not mock_event
            assert not stream._queue