Beispiel #1
0
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)))
Beispiel #2
0
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))
Beispiel #3
0
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())
Beispiel #4
0
async def test_accumulate_empty_iterable():
    """Check if accumulate works with empty iterables."""
    assert (await aitertools.alist(
        aitertools.accumulate([])
    )) == []
Beispiel #5
0
async def test_accumulate_single_item():
    """Check if accumulate works on an iterable of one item."""
    assert (await aitertools.alist(
        aitertools.accumulate([7])
    )) == [7]
Beispiel #6
0
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]))
Beispiel #7
0
async def test_accumulate_non_numeric():
    """Check if accumulate works with non-numeric types."""
    assert (await aitertools.alist(
        aitertools.accumulate('abc')
    )) == ['a', 'ab', 'abc']
Beispiel #8
0
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]
Beispiel #9
0
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]
Beispiel #10
0
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))
Beispiel #11
0
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
Beispiel #12
0
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, []]))