Ejemplo n.º 1
0
def test_splits_empty_iterable():
    gen = split_iterable(iter(""), 5)

    assert isgenerator(gen)

    for val in gen:
        print(val)
        pytest.fail("should be an empty generator")
Ejemplo n.º 2
0
def test_consumes_given_iterable():
    it = iter("asddsa")
    gen = split_iterable(it, 3)

    gen = list(gen)  # consumes result

    for val in it:
        pytest.fail("should have been consumed")
Ejemplo n.º 3
0
def test_splits_left_to_right():
    gen = split_iterable("asddsa", 3)

    val1 = next(gen)
    val2 = next(gen)

    assert val1 == ["a", "s", "d"]
    assert val2 == ["d", "s", "a"]
Ejemplo n.º 4
0
def test_imperfectly_yields_all_parts():
    gen = split_iterable("asd", 2)

    val1 = next(gen)
    val2 = next(gen)

    assert len(val1) == 2
    assert len(val2) == 1
Ejemplo n.º 5
0
def test_splists_perfectly():
    gen = split_iterable("asddsa", 3)

    i = 0
    for val in gen:
        assert len(val) == 3
        i += 1

    assert i == 2