예제 #1
0
def test_split_failure6():
    # more than one keep* parameter
    with pytest.raises(ValueError) as exc:
        split(toT([1, 2, 3, 4]),
              T(2),
              eq=True,
              keep_before=True,
              keep_after=True)
    assert '`keep`, `keep_before`, `keep_after`' in str(exc.value)
예제 #2
0
def test_split_pickle3(protocol):
    l = [T(1), T(2), T(3), T(4), T(5), T(3), T(7), T(8)]
    spl = split(l, equalsthreeT, keep=True)
    assert next(spl) == toT([1, 2])
    x = pickle.dumps(spl, protocol=protocol)
    assert list(
        pickle.loads(x)) == [toT(i) for i in [[3], [4, 5], [3], [7, 8]]]
예제 #3
0
def test_traverse():
    """To test the traverse implementation we call gc.collect() while instances
    of all the C objects are still valid."""
    acc = iteration_utilities.accumulate([])
    app = iteration_utilities.applyfunc(lambda x: x, 1)
    cha = iteration_utilities.chained(int, float)
    cla = iteration_utilities.clamp([], 0, 1)
    com = iteration_utilities.complement(int)
    con = iteration_utilities.constant(1)
    dee = iteration_utilities.deepflatten([])
    dup = iteration_utilities.duplicates([])
    fli = iteration_utilities.flip(int)
    gro = iteration_utilities.grouper([], 2)
    ine = iteration_utilities.intersperse([], 1)
    iik = iteration_utilities.ItemIdxKey(10, 2)
    ite = iteration_utilities.iter_except(int, TypeError)
    mer = iteration_utilities.merge([])
    nth = iteration_utilities.nth(1)
    pac = iteration_utilities.packed(int)
    par = iteration_utilities.partial(int, 10)
    rep = iteration_utilities.replicate([], 3)
    rou = iteration_utilities.roundrobin([])
    see = iteration_utilities.Seen()
    sid = iteration_utilities.sideeffects([], lambda x: x)
    spl = iteration_utilities.split([], lambda x: True)
    sta = iteration_utilities.starfilter(lambda x: True, [])
    suc = iteration_utilities.successive([])
    tab = iteration_utilities.tabulate(int)
    une = iteration_utilities.unique_everseen([])
    unj = iteration_utilities.unique_justseen([])
    gc.collect()
예제 #4
0
def test_split_attributes1():
    it = split([], iteration_utilities.return_False)
    assert it.key is iteration_utilities.return_False
    assert it.maxsplit == -1
    assert not it.keep
    assert not it.keep_before
    assert not it.keep_after
    assert not it.eq

    it = split([], iteration_utilities.return_False, keep=True)
    assert it.keep
    assert not it.keep_before
    assert not it.keep_after

    it = split([], iteration_utilities.return_False, keep_before=True)
    assert not it.keep
    assert it.keep_before
    assert not it.keep_after

    it = split([], iteration_utilities.return_False, keep_after=True)
    assert not it.keep
    assert not it.keep_before
    assert it.keep_after
예제 #5
0
def test_split_normal2():
    assert list(split([T(1), T(2), T(3)],
                      lambda x: x.value == 3)) == [toT([1, 2])]
예제 #6
0
def test_split_normal3():
    # using a generator
    assert list(split((i for i in [T(1), T(2), T(3)]),
                      lambda x: x.value == 2)) == [[T(1)], [T(3)]]
예제 #7
0
def test_split_pickle4(protocol):
    l = [T(1), T(2), T(3), T(4), T(5), T(3), T(7), T(8)]
    spl = split(l, equalsthreeT, maxsplit=1)
    assert next(spl) == toT([1, 2])
    x = pickle.dumps(spl, protocol=protocol)
    assert list(pickle.loads(x)) == [toT([4, 5, 3, 7, 8])]
예제 #8
0
def test_split_pickle5(protocol):
    l = [T(1), T(2), T(3), T(4), T(5), T(3), T(7), T(8)]
    spl = split(l, T(3), eq=True)
    assert next(spl) == toT([1, 2])
    x = pickle.dumps(spl, protocol=protocol)
    assert list(pickle.loads(x)) == [toT([4, 5]), toT([7, 8])]
예제 #9
0
def test_split_eq1():
    assert list(split([T(1), T(2), T(3), T(2), T(5)], T(2),
                      eq=True)) == [[T(1)], [T(3)], [T(5)]]
예제 #10
0
def test_split_empty1():
    assert list(split([], lambda x: False)) == []
예제 #11
0
def test_split_normal1():
    assert list(split([T(1), T(2), T(3)], lambda x: x.value == 2)) == [[T(1)],
                                                                       [T(3)]]
예제 #12
0
def test_split_keep_after2():
    assert list(
        split([T(1), T(2), T(3)], lambda x: x.value == 3,
              keep_after=True)) == [[T(1), T(2)], [T(3)]]
예제 #13
0
def test_split_failure12():
    # Changing next method
    with pytest.raises(_hf.CacheNext.EXC_TYP, match=_hf.CacheNext.EXC_MSG):
        list(split(_hf.CacheNext(1), lambda x: x == 10))
예제 #14
0
def test_split_copy1():
    _hf.iterator_copy(split(toT(range(1, 9)), equalsthreeT))
예제 #15
0
def test_split_failure11():
    # maxsplit <= -2
    with pytest.raises(ValueError, match='`maxsplit`'):
        split(toT([1, 2, 3, 4]), T(2), eq=True, maxsplit=-2)
예제 #16
0
def test_split_failure10():
    # Too few arguments
    with pytest.raises(TypeError):
        split()
예제 #17
0
def test_split_failure9():
    # Test that a failing iterator doesn't raise a SystemError
    with pytest.raises(_hf.FailNext.EXC_TYP, match=_hf.FailNext.EXC_MSG):
        next(split(_hf.FailNext(offset=1), iteration_utilities.return_False))
예제 #18
0
def test_split_keep1():
    assert list(split([T(1), T(2), T(3)], lambda x: x.value == 2,
                      keep=True)) == [[T(1)], [T(2)], [T(3)]]
예제 #19
0
def test_split_failure1():
    with pytest.raises(_hf.FailIter.EXC_TYP, match=_hf.FailIter.EXC_MSG):
        split(_hf.FailIter(), lambda x: False)
예제 #20
0
def test_split_keep_before2():
    assert list(
        split([T(1), T(2), T(3)], lambda x: x.value == 3,
              keep_before=True)) == [[T(1), T(2), T(3)]]
예제 #21
0
def test_split_pickle1(protocol):
    l = [T(1), T(2), T(3), T(4), T(5), T(3), T(7), T(8)]
    spl = split(l, equalsthreeT)
    x = pickle.dumps(spl, protocol=protocol)
    assert list(pickle.loads(x)) == [[T(1), T(2)], [T(4), T(5)], [T(7), T(8)]]
예제 #22
0
def test_split_maxsplit2():
    assert list(
        split([T(1), T(2), T(3), T(4), T(5)],
              lambda x: x.value % 2 == 0,
              maxsplit=2)) == [[T(1)], [T(3)], [T(5)]]
예제 #23
0
def test_split_failure2():
    # func fails
    with pytest.raises(TypeError):
        list(split([T(1), T(2), T(3)], lambda x: T(x.value + 'a')))
예제 #24
0
def test_split_failure_setstate2():
    _hf.iterator_setstate_empty_fail(split(toT(range(1, 9)), equalsthreeT))
예제 #25
0
def test_split_failure3():
    # cmp fails
    with pytest.raises(TypeError):
        list(split([T(1), T(2), T(3)], T('a'), eq=True))