Ejemplo n.º 1
0
async def test_islice_consumption():
    """Check that islice does not overly consume the iterable."""
    iterable = await aitertools.aiter(range(10))
    assert (await aitertools.alist(
        aitertools.islice(iterable, 3)
    )) == list(range(3))
    assert (await aitertools.alist(iterable)) == list(range(3, 10))
Ejemplo n.º 2
0
async def test_islice_no_stop():
    """Check that islice exhausts the iterable when no stop is given."""
    assert (await aitertools.alist(
        aitertools.islice(range(10), None)
    )) == list(range(10))

    assert (await aitertools.alist(
        aitertools.islice(range(10), None, None)
    )) == list(range(10))

    assert (await aitertools.alist(
        aitertools.islice(range(10), None, None, None)
    )) == list(range(10))

    assert (await aitertools.alist(
        aitertools.islice(range(10), 2, None)
    )) == list(range(2, 10))

    assert (await aitertools.alist(
        aitertools.islice(range(10), 1, None, 2)
    )) == list(range(1, 10, 2))
Ejemplo n.º 3
0
async def test_islice_invalid_arguments(args):
    """Check that islice raises ValueError when input is invalid."""
    with pytest.raises(ValueError):

        await aitertools.anext(aitertools.islice(range(10), *args))
Ejemplo n.º 4
0
async def test_islice_exausted_iterable(slice_args, range_args):
    """Check that islice stops when the wrapped iterable is exhausted."""
    assert (await aitertools.alist(
        aitertools.islice(range(100), *slice_args)
    )) == list(range(*range_args))
Ejemplo n.º 5
0
async def test_islice_matches_range(args):
    """Check happy path for islice using equivalent range arguments."""
    assert (await aitertools.alist(
        aitertools.islice(range(100), *args)
    )) == list(range(*args))
Ejemplo n.º 6
0
 async def generator():
     with open(file_path) as csvf:
         async for line in aitertools.islice(csvf, slice_size):
             yield line.encode("utf-8")