Esempio 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
Esempio 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))
Esempio 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
Esempio 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), [])
Esempio n. 5
0
def test_next():
    fiter = FIt([1])
    fiter2 = FIt([1])

    assert fiter.next() == next(fiter2)
    with pytest.raises(StopIteration):
        fiter.next()
Esempio n. 6
0
def test_chunk():
    fiter = FIt(range(5))
    expected = [[0, 1], [2, 3], [4]]
    assert_equal_it(fiter.chunk(2), expected)
Esempio 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)
Esempio n. 8
0
def test_flatten_nostr():
    fiter = FIt([1, [2, "potato"]])
    assert_equal_it(fiter.flatten(split_strings=True), [1, 2] + list("potato"))
Esempio n. 9
0
def test_getitem_neg_nolen(lst):
    fiter = FIt(iter(lst))
    with pytest.raises(ValueError):
        fiter[-1]
Esempio n. 10
0
def test_any(lst, expected):
    fiter = FIt(lst)
    assert fiter.any() == expected
Esempio n. 11
0
def test_ensure_FIt(lst):
    assert isinstance(ensure_FIt(lst), FIt)
    fiter = FIt(lst)
    assert ensure_FIt(fiter) is fiter
Esempio n. 12
0
def test_repeat():
    it = FIt.repeat(1, 5)
    assert len(it) == 5
    assert list(it) == [1] * 5
Esempio 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))
Esempio n. 14
0
def test_range(args):
    assert_equal_it(FIt.range(*args), range(*args))
Esempio n. 15
0
def test_getitem_neg(lst):
    fiter = FIt(lst)
    assert fiter[-1] == lst[-1]
Esempio n. 16
0
def test_getitem(lst):
    fiter = FIt(lst)
    assert fiter[2] == lst[2]
Esempio n. 17
0
def test_all(lst, expected):
    fiter = FIt(lst)
    assert fiter.all() == expected
Esempio 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)
Esempio n. 19
0
def test_instantiate_nolen(lst):
    it = FIt(iter(lst))
    assert it.length is None
    with pytest.raises(TypeError):
        len(it)
Esempio n. 20
0
def test_islice_neg(lst):
    fiter = FIt(lst)
    assert_equal_it(fiter.islice(5, -2), lst[5:-2])
Esempio n. 21
0
def test_instantiate(lst):
    it = FIt(lst)
    assert it.length == len(it) == len(lst)
Esempio 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])
Esempio n. 23
0
def test_instantiate_explicit_len(lst):
    it = FIt(iter(lst), len(lst))
    assert it.length == len(it) == len(lst)
Esempio 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]])
Esempio n. 25
0
def test_to(lst):
    assert FIt(lst).to(set) == set(lst)
Esempio n. 26
0
def test_flatten_str():
    fiter = FIt([1, [2, "potato"]])
    assert_equal_it(fiter.flatten(), [1, 2, "potato"])