コード例 #1
0
def test_first_n_no_filling():
    from xoutil.iterators import first_n
    try:
        next(first_n((), 1))
        assert False, 'Should have raised an StopIteration'
    except StopIteration:
        pass
    except:
        assert False, 'Should have raised an StopIteration'
コード例 #2
0
def test_first_n_simple():
    from xoutil.iterators import first_n
    assert list(first_n(range(100), 10, 0)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
コード例 #3
0
def test_first_n_repeat_filling_by_repeating():
    from xoutil.iterators import first_n
    from itertools import repeat
    assert list(first_n((), 10, '0')) == list(repeat('0', 10))
コード例 #4
0
def test_first_n_filling_by_cycling():
    from xoutil.iterators import first_n
    assert list(first_n((), 10, range(5))) == [0, 1, 2, 3, 4] * 2