async def test_accumulate_unexpected_kwarg(): """Check that TypeError is raised when given nonsense kwargs.""" with pytest.raises(TypeError): await aitertools.alist(aitertools.accumulate(x=range(10)))
async def test_accumulate_too_many_args(): """Check if TypeError is raised on too many args.""" with pytest.raises(TypeError): await aitertools.alist(aitertools.accumulate(range(10), 5, 6))
async def test_accumulate_too_few_args(): """Check if TypeError is raised on too few args.""" with pytest.raises(TypeError): await aitertools.alist(aitertools.accumulate())
async def test_accumulate_empty_iterable(): """Check if accumulate works with empty iterables.""" assert (await aitertools.alist( aitertools.accumulate([]) )) == []
async def test_accumulate_single_item(): """Check if accumulate works on an iterable of one item.""" assert (await aitertools.alist( aitertools.accumulate([7]) )) == [7]
async def test_accumulate_multiple_types(type_): """Check if accumulate works with multiple types.""" assert (await aitertools.alist( aitertools.accumulate(map(type_, range(10))) )) == list(map(type_, [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]))
async def test_accumulate_non_numeric(): """Check if accumulate works with non-numeric types.""" assert (await aitertools.alist( aitertools.accumulate('abc') )) == ['a', 'ab', 'abc']
async def test_accumulate_kwarg(): """Check if accumulate works with kwargs.""" assert (await aitertools.alist( aitertools.accumulate(iterable=range(10)) )) == [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
async def test_accumulate_matches_sync(): """Check if async accumulate matches sync.""" assert (await aitertools.alist( aitertools.accumulate(range(10)) )) == [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
async def test_accumulate_unary_func(): """Check that TypeError is raised when accumulate with a unary function.""" with pytest.raises(TypeError): await aitertools.alist(aitertools.accumulate(range(10), chr))
async def test_accumulate_binary_funcs(seed, func, expected): """Check if accumulate correctly applies custom binary functions.""" assert (await aitertools.alist( aitertools.accumulate(seed, func) )) == expected
async def test_accumulate_args_dont_add(): """Check if TypeError is raised when iterable items don't add.""" with pytest.raises(TypeError): await aitertools.alist(aitertools.accumulate([1, []]))