Esempio n. 1
0
async def test_takewhile_too_few_args():
    """Check that takewhile raises TypeError when too few args."""
    with pytest.raises(TypeError):

        await aitertools.anext(aitertools.takewhile())

    with pytest.raises(TypeError):

        await aitertools.anext(aitertools.takewhile(lambda x: x))
Esempio n. 2
0
async def test_takewhile_too_many_args():
    """Check that takewhile raises TypeError when too many args."""
    with pytest.raises(TypeError):

        await aitertools.anext(aitertools.takewhile(bool, range(1), 'a'))
Esempio n. 3
0
async def test_takewhile_empty_iterable():
    """Check that takewhile is empty when the iterable is empty."""
    assert (await aitertools.alist(
        aitertools.takewhile(lambda x: x < 5, ())
    )) == []
Esempio n. 4
0
async def test_takewhile_uses_predicate():
    """Check the takewhile happy path. Get values until predicate is False."""
    assert (await aitertools.alist(
        aitertools.takewhile(lambda x: x < 5, range(10))
    )) == [x for x in range(10) if x < 5]