def test_nth_failures3(): with pytest.raises(IndexError): nth(1)([T(0)], pred=bool)
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])
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])
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))
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))
def test_nth_predtruthyretpred5(): assert nth(2)([T(0), T(1), T(2), T(3)], pred=bool) == T(3)
def test_nth_predtruthyretpred7(): assert nth(2)([T(0), T(1), T(2), T(3)], pred=lambda x: x**T(2)) == T(3)
def test_nth_normal1(): assert nth(1)([T(1), T(2), T(3)]) == T(2)
def test_nth_normal2(): assert nth(2)(map(T, range(10))) == T(2)
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)
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)
def test_nth_failures10(): # indexerror with generator with pytest.raises(IndexError): nth(1)((i for i in [T(0)]), pred=bool)
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)
def test_nth_failures4(): with pytest.raises(TypeError): nth(1)([T('a'), T('b')], pred=lambda x: abs(x.value))
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)
def test_nth_nopred_retpred1(): assert nth(2)(toT(range(10)), retpred=1) == T(2)
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)
def test_nth_pred1(): # With pred assert nth(1)([T(0), T(1), T(2)], pred=bool) == T(2)
def test_nth_predtruthyretpred6(): assert nth(2)([T(0), T(1), T(2), T(3)], pred=bool, retpred=True)
def test_nth_pred2(): assert nth(1)([T(0), T(1), T(2)], pred=None) == T(2)
def test_roundrobin_copy1(): _hf.iterator_copy(roundrobin([T(1), T(2), T(3), T(4)]))
def test_nth_pred3(): assert nth(0)([T(0)] * 100 + [T(1)], pred=bool) == T(1)
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))
def test_nth_pred4(): assert nth(1)([[T(0)], [T(1), T(2)]] * 2, pred=lambda x: len(x) > 1) == [T(1), T(2)]
def test_roundrobin_failure_setstate8(): _hf.iterator_setstate_empty_fail( roundrobin([T(1)], [T(1), T(2), T(3), T(4)]))
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)
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])
def test_nth_predtruthyretpred2(): assert not nth(1)( [T(0), T(1), T(2), T(3), T(0)], pred=bool, truthy=False, retpred=True)
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)
def test_nth_default3(): # generator assert nth(1)( (i for i in [T(0), T(0), T(0)]), default=None, pred=bool) is None