示例#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)))
示例#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))
示例#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())
示例#4
0
async def test_accumulate_empty_iterable():
    """Check if accumulate works with empty iterables."""
    assert (await aitertools.alist(
        aitertools.accumulate([])
    )) == []
示例#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]
示例#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]))
示例#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']
示例#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]
示例#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]
示例#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))
示例#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
示例#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, []]))