Exemplo n.º 1
0
def test_add_with_length_hint():
    one = ChIter(range(5))
    two = ChIter(range(5, 10))
    i = one + two
    length = length_hint(one) + length_hint(two)

    assert length_hint(i) == length
Exemplo n.º 2
0
def test_groupby():
    iterable = [1, 1, 3, 2, 2]

    i = ChIter(iterable).groupby()

    assert isinstance(i, ChIter)
    assert [(k, list(g)) for k, g in itertools.groupby(iterable)] == [(k, list(g)) for k, g in i]
Exemplo n.º 3
0
def test_dict():
    items = [(1, 2), (3, 4)]

    i = ChIter(items).dict()

    assert isinstance(i, dict)
    assert dict(items) == i
Exemplo n.º 4
0
def test_takewhile():
    def predicate(x):
        return x <= 2

    i = ChIter(range(5)).takewhile(predicate)

    assert isinstance(i, ChIter)
    assert list(itertools.takewhile(predicate, range(5))) == list(i)
Exemplo n.º 5
0
def test_filterfalse():
    def func(x):
        return x % 2

    i = ChIter(range(5)).filterfalse(func)

    assert isinstance(i, ChIter)
    assert list(itertools.filterfalse(func, range(5))) == list(i)
Exemplo n.º 6
0
def test_zip_longest_fillvalue():
    data = [(1, 2), (1,)]
    empty_value = object()

    i = ChIter(data).zip_longest(fillvalue=empty_value)

    assert isinstance(i, ChIter)
    assert list(itertools.zip_longest(*data, fillvalue=empty_value)) == list(i)
Exemplo n.º 7
0
def test_dropwhile():
    def func(x):
        return x > 2

    i = ChIter(range(5)).dropwhile(func)

    assert isinstance(i, ChIter)
    assert list(itertools.dropwhile(func, range(5))) == list(i)
Exemplo n.º 8
0
def test_tee():
    i = ChIter(range(5)).tee()

    assert isinstance(i, ChIter)
    i1, i2 = i

    assert isinstance(i1, ChIter)
    assert isinstance(i2, ChIter)

    assert list(i1) == list(i2)
Exemplo n.º 9
0
def test_groupby_key():
    def key(x):
        return x % 2

    iterable = [1, 1, 3, 2, 2]

    i = ChIter(iterable).groupby(key)

    assert isinstance(i, ChIter)
    assert [(k, list(g)) for k, g in itertools.groupby(iterable, key)] == [(k, list(g)) for k, g in i]
Exemplo n.º 10
0
def test_tee_n():
    i = ChIter(range(5)).tee(3)

    assert isinstance(i, ChIter)
    i1, i2, i3 = i

    assert isinstance(i1, ChIter)
    assert isinstance(i2, ChIter)
    assert isinstance(i3, ChIter)

    assert list(i1) == list(i2) == list(i3)
Exemplo n.º 11
0
def test_starmap_length_hint():
    i = ChIter(enumerate(range(5))).starmap(pow)

    assert length_hint(enumerate(range(5))) == length_hint(i)
Exemplo n.º 12
0
def test_next_empty():
    with pytest.raises(StopIteration):
        next(ChIter([]))
Exemplo n.º 13
0
def test_next_with_length_hint():
    i = ChIter([None])

    assert length_hint(i) == 1
    next(i)
    assert length_hint(i) == 0
Exemplo n.º 14
0
def test_next():
    item = next(ChIter([None]))
    assert item is None
Exemplo n.º 15
0
def test_iterator():
    iterator = iter(ChIter([]))
    assert isinstance(iterator, Iterator)
Exemplo n.º 16
0
def test_from_iterables_with_length_hint():
    i = ChIter.from_iterables(range(5), range(5, 10))

    assert length_hint(i) == length_hint(range(10))
Exemplo n.º 17
0
def test_add_right_not_iter():
    with pytest.raises(TypeError):
        None + ChIter(range(5, 10))
Exemplo n.º 18
0
def test_add_left():
    i = ChIter(range(5)) + range(5, 10)

    assert isinstance(i, ChIter)
    assert list(i) == list(range(10))
Exemplo n.º 19
0
def test_add_right():
    i = range(5) + ChIter(range(5, 10))

    assert isinstance(i, ChIter)
    assert list(i) == list(range(10))
Exemplo n.º 20
0
def test_compress():
    selectors = [True, False, True]
    i = ChIter(range(5)).compress(selectors)

    assert isinstance(i, ChIter)
    assert list(itertools.compress(range(5), selectors)) == list(i)
Exemplo n.º 21
0
def test_accumulate():
    i = ChIter(range(5)).accumulate()

    assert isinstance(i, ChIter)
    assert list(i) == list(itertools.accumulate(range(5)))
Exemplo n.º 22
0
def test_combinations_with_replacement():
    i = ChIter(range(5)).combinations_with_replacement(2)

    assert isinstance(i, ChIter)
    assert list(itertools.combinations_with_replacement(range(5), 2)) == list(i)
Exemplo n.º 23
0
def test_combinations():
    i = ChIter(range(5)).combinations(2)

    assert isinstance(i, ChIter)
    assert list(itertools.combinations(range(5), 2)) == list(i)
Exemplo n.º 24
0
def test_cycle():
    i = ChIter([None]).cycle()

    assert isinstance(i, ChIter)
    assert list(zip(i, range(5))) == list(zip(itertools.cycle([None]), range(5)))
Exemplo n.º 25
0
def test_add_left_not_iter():
    with pytest.raises(TypeError):
        ChIter(range(5)) + None
Exemplo n.º 26
0
def test_zip_longest():
    i = ChIter(enumerate(range(5))).zip_longest()

    assert isinstance(i, ChIter)
    assert list(itertools.zip_longest(*enumerate(range(5)))) == list(i)
Exemplo n.º 27
0
def test_as_iterator():
    assert isinstance(ChIter([]), Iterator)
Exemplo n.º 28
0
def test_from_iterables():
    i = ChIter.from_iterables(range(5), range(5, 10))

    assert isinstance(i, ChIter)
    assert list(i) == list(range(10))
Exemplo n.º 29
0
def test_length_hint():
    i = length_hint(ChIter(range(5)))

    assert isinstance(i, int)
    assert i == length_hint(range(5))
Exemplo n.º 30
0
def test_zip_longest_length_hint():
    i = ChIter(enumerate(range(5))).zip_longest()

    assert length_hint(enumerate(range(5))) == length_hint(i)