예제 #1
0
    async def test_streamable_sync_async_iterator(self):
        items = list(range(20))

        def get_async_iterator():
            class AIterator:
                def __init__(self):
                    self._index = 0
                    self._items = items

                def __aiter__(self):
                    return self

                def __len__(self):
                    return len(self._items)

                async def __anext__(self):
                    if self._index >= len(self):
                        raise StopAsyncIteration

                    self._index += 1
                    return self._items[self._index - 1]

            return AIterator()

        streamable = Streamable(get_async_iterator)
        result = [i async for i in streamable()]
        assert result == items
예제 #2
0
    async def test_streamable_async_list(self):
        items = list(range(20))

        async def get_list():
            return items

        streamable = Streamable(get_list)
        result = [i async for i in streamable()]
        assert result == items
예제 #3
0
    async def test_streamable_sync_generator(self):
        items = list(range(20))

        def sync_generator():
            for i in items:
                yield i

        streamable = Streamable(sync_generator)
        result = [i async for i in streamable()]
        assert result == items