Beispiel #1
0
def test_nth_failures3():
    with pytest.raises(IndexError):
        nth(1)([T(0)], pred=bool)
Beispiel #2
0
def test_roundrobin_pickle1():
    rr = roundrobin([T(1), T(2), T(3)], [T(1), T(2), T(3)])
    assert next(rr) == T(1)
    x = pickle.dumps(rr)
    assert list(pickle.loads(x)) == toT([1, 2, 2, 3, 3])
Beispiel #3
0
def test_roundrobin_normal4():
    # generator
    assert list(roundrobin((i for i in [T(1), T(2), T(3)]),
                           (i for i in [T(1)]),
                           (i for i in [T(1), T(2)]))
                ) == toT([1, 1, 1, 2, 2, 3])
Beispiel #4
0
def test_roundrobin_failure_setstate3():
    # setstate numactive <= active
    rr = roundrobin([T(1), T(2), T(3), T(4)])
    with pytest.raises(ValueError):
        rr.__setstate__((1, 1))
Beispiel #5
0
def test_roundrobin_failure_setstate6():
    # setstate numactive > len(iteratortuple) (after exhausting one iterable)
    rr = roundrobin([T(1)], [T(1), T(2), T(3), T(4)])
    assert [i for i in itertools.islice(rr, 3)] == toT([1, 1, 2])
    with pytest.raises(ValueError):
        rr.__setstate__((2, 1))
Beispiel #6
0
def test_nth_predtruthyretpred5():
    assert nth(2)([T(0), T(1), T(2), T(3)], pred=bool) == T(3)
Beispiel #7
0
def test_nth_predtruthyretpred7():
    assert nth(2)([T(0), T(1), T(2), T(3)], pred=lambda x: x**T(2)) == T(3)
Beispiel #8
0
def test_nth_normal1():
    assert nth(1)([T(1), T(2), T(3)]) == T(2)
Beispiel #9
0
def test_nth_normal2():
    assert nth(2)(map(T, range(10))) == T(2)
Beispiel #10
0
def test_nth_failures14():
    # evaluating as boolean fails
    with pytest.raises(_hf.FailBool.EXC_TYP, match=_hf.FailBool.EXC_MSG):
        nth(1)([T(0)], pred=lambda x: _hf.FailBool(), truthy=0)
Beispiel #11
0
def test_nth_pickle1(protocol):
    x = pickle.dumps(nth(2), protocol=protocol)
    assert pickle.loads(x)([T(1), T(2), T(3), T(4)]) == T(3)
Beispiel #12
0
def test_nth_failures10():
    # indexerror with generator
    with pytest.raises(IndexError):
        nth(1)((i for i in [T(0)]), pred=bool)
Beispiel #13
0
def test_nth_failures9():
    # too few arguments for __call__
    with pytest.raises(ValueError, match='`retpred` or `retidx`'):
        nth(1)([T(0), T(1), T(2)], retpred=1, retidx=1)
Beispiel #14
0
def test_nth_failures4():
    with pytest.raises(TypeError):
        nth(1)([T('a'), T('b')], pred=lambda x: abs(x.value))
Beispiel #15
0
def test_nth_predtruthyretpred3():
    assert nth(1)([T(0), T(2), T(3), T(0)],
                  pred=lambda x: x**T(2),
                  truthy=False) == T(0)
Beispiel #16
0
def test_nth_nopred_retpred1():
    assert nth(2)(toT(range(10)), retpred=1) == T(2)
Beispiel #17
0
def test_nth_predtruthyretpred4():
    assert nth(1)(toT([0, 1, 2, 3, 0]),
                  pred=lambda x: x**T(2),
                  truthy=False,
                  retpred=True) == T(0)
Beispiel #18
0
def test_nth_pred1():
    # With pred
    assert nth(1)([T(0), T(1), T(2)], pred=bool) == T(2)
Beispiel #19
0
def test_nth_predtruthyretpred6():
    assert nth(2)([T(0), T(1), T(2), T(3)], pred=bool, retpred=True)
Beispiel #20
0
def test_nth_pred2():
    assert nth(1)([T(0), T(1), T(2)], pred=None) == T(2)
Beispiel #21
0
def test_roundrobin_copy1():
    _hf.iterator_copy(roundrobin([T(1), T(2), T(3), T(4)]))
Beispiel #22
0
def test_nth_pred3():
    assert nth(0)([T(0)] * 100 + [T(1)], pred=bool) == T(1)
Beispiel #23
0
def test_roundrobin_failure_setstate5():
    # setstate numactive > len(iteratortuple)
    rr = roundrobin([T(1), T(2), T(3), T(4)])
    with pytest.raises(ValueError):
        rr.__setstate__((2, 1))
Beispiel #24
0
def test_nth_pred4():
    assert nth(1)([[T(0)], [T(1), T(2)]] * 2,
                  pred=lambda x: len(x) > 1) == [T(1), T(2)]
Beispiel #25
0
def test_roundrobin_failure_setstate8():
    _hf.iterator_setstate_empty_fail(
            roundrobin([T(1)], [T(1), T(2), T(3), T(4)]))
Beispiel #26
0
def test_nth_predtruthyretpred1():
    # pred with truthy/retpred
    assert nth(1)([T(0), T(2), T(3), T(0)], pred=bool, truthy=False) == T(0)
Beispiel #27
0
def test_roundrobin_normal3():
    assert list(roundrobin([T(1), T(2)], [T(1), T(2), T(3)], [T(1)]
                           )) == toT([1, 1, 1, 2, 2, 3])
Beispiel #28
0
def test_nth_predtruthyretpred2():
    assert not nth(1)(
        [T(0), T(1), T(2), T(3), T(0)], pred=bool, truthy=False, retpred=True)
Beispiel #29
0
def test_roundrobin_failure2():
    with pytest.raises(_hf.FailIter.EXC_TYP) as exc:
        roundrobin([T(1)], _hf.FailIter())
    assert _hf.FailIter.EXC_MSG in str(exc)
Beispiel #30
0
def test_nth_default3():
    # generator
    assert nth(1)(
        (i for i in [T(0), T(0), T(0)]), default=None, pred=bool) is None