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))
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'))
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, ()) )) == []
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]