Exemplo n.º 1
0
def test_length():
    fiter = FIt(range(5))
    assert len(fiter) == 5
    next(fiter)
    assert len(fiter) == 4
    fiter.peek()
    assert len(fiter) == 4
Exemplo n.º 2
0
def test_starmap():
    lst = [(x, x**2) for x in range(10)]
    fiter = FIt(lst)

    def fn(x, y):
        return x + y

    assert_equal_it(fiter.starmap(fn), starmap(fn, lst))
Exemplo n.º 3
0
def fiter(request, lst):
    if request.param == "list":
        fiter = FIt(lst)
        assert len_or_none(fiter) is not None
        return fiter
    else:
        fiter = FIt(iter(lst))
        assert len_or_none(fiter) is None
        return fiter
Exemplo n.º 4
0
def test_sliding_window():
    fiter = FIt(range(5))
    expected = [(0, 1, 2), (1, 2, 3), (2, 3, 4)]
    assert_equal_it(fiter.sliding_window(3), expected)

    fiter2 = FIt(range(5))
    assert_equal_it(fiter2.sliding_window(10), [])
Exemplo n.º 5
0
def test_next():
    fiter = FIt([1])
    fiter2 = FIt([1])

    assert fiter.next() == next(fiter2)
    with pytest.raises(StopIteration):
        fiter.next()
Exemplo n.º 6
0
def test_chunk():
    fiter = FIt(range(5))
    expected = [[0, 1], [2, 3], [4]]
    assert_equal_it(fiter.chunk(2), expected)
Exemplo n.º 7
0
def test_flatten_0():
    lst = [1, 2, [3, 4], [5, [6, 7]]]
    fiter = FIt(lst)
    assert_equal_it(fiter.flatten(0), lst)
Exemplo n.º 8
0
def test_flatten_nostr():
    fiter = FIt([1, [2, "potato"]])
    assert_equal_it(fiter.flatten(split_strings=True), [1, 2] + list("potato"))
Exemplo n.º 9
0
def test_getitem_neg_nolen(lst):
    fiter = FIt(iter(lst))
    with pytest.raises(ValueError):
        fiter[-1]
Exemplo n.º 10
0
def test_any(lst, expected):
    fiter = FIt(lst)
    assert fiter.any() == expected
Exemplo n.º 11
0
def test_ensure_FIt(lst):
    assert isinstance(ensure_FIt(lst), FIt)
    fiter = FIt(lst)
    assert ensure_FIt(fiter) is fiter
Exemplo n.º 12
0
def test_repeat():
    it = FIt.repeat(1, 5)
    assert len(it) == 5
    assert list(it) == [1] * 5
Exemplo n.º 13
0
def test_count(fiter, lst):
    fiter = FIt.count(2, 20)
    other = count(2, 20)
    assert_equal_it(islice(fiter, 20), islice(other, 20))
Exemplo n.º 14
0
def test_range(args):
    assert_equal_it(FIt.range(*args), range(*args))
Exemplo n.º 15
0
def test_getitem_neg(lst):
    fiter = FIt(lst)
    assert fiter[-1] == lst[-1]
Exemplo n.º 16
0
def test_getitem(lst):
    fiter = FIt(lst)
    assert fiter[2] == lst[2]
Exemplo n.º 17
0
def test_all(lst, expected):
    fiter = FIt(lst)
    assert fiter.all() == expected
Exemplo n.º 18
0
def test_interleave(wrapped):
    fiter = FIt(wrapped)
    mix_with = range(5, 10)
    expected = [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]
    assert_equal_it(fiter.interleave(mix_with), expected)
Exemplo n.º 19
0
def test_instantiate_nolen(lst):
    it = FIt(iter(lst))
    assert it.length is None
    with pytest.raises(TypeError):
        len(it)
Exemplo n.º 20
0
def test_islice_neg(lst):
    fiter = FIt(lst)
    assert_equal_it(fiter.islice(5, -2), lst[5:-2])
Exemplo n.º 21
0
def test_instantiate(lst):
    it = FIt(lst)
    assert it.length == len(it) == len(lst)
Exemplo n.º 22
0
def test_flatten():
    fiter = FIt([1, 2, [3, 4], [5, [6, 7]]])
    assert_equal_it(fiter.flatten(), [1, 2, 3, 4, 5, 6, 7])
Exemplo n.º 23
0
def test_instantiate_explicit_len(lst):
    it = FIt(iter(lst), len(lst))
    assert it.length == len(it) == len(lst)
Exemplo n.º 24
0
def test_flatten_levels():
    fiter = FIt([1, 2, [3, 4], [5, [6, 7]]])
    assert_equal_it(fiter.flatten(levels=1), [1, 2, 3, 4, 5, [6, 7]])
Exemplo n.º 25
0
def test_to(lst):
    assert FIt(lst).to(set) == set(lst)
Exemplo n.º 26
0
def test_flatten_str():
    fiter = FIt([1, [2, "potato"]])
    assert_equal_it(fiter.flatten(), [1, 2, "potato"])