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()
def test_sideeffects_failure_lengthhint2(): # This only checks for overflow if the length_hint is above PY_SSIZE_T_MAX of_it = _hf.OverflowLengthHint(toT([1, 2, 3]), sys.maxsize + 1) it = sideeffects(of_it, return_None) with pytest.raises(OverflowError): operator.length_hint(it) with pytest.raises(OverflowError): list(it)
def test_sideeffects_failure_lengthhint1(): f_it = _hf.FailLengthHint(toT([1, 2, 3])) it = sideeffects(f_it, return_None) with pytest.raises(_hf.FailLengthHint.EXC_TYP, match=_hf.FailLengthHint.EXC_MSG): operator.length_hint(it) with pytest.raises(_hf.FailLengthHint.EXC_TYP, match=_hf.FailLengthHint.EXC_MSG): list(it)
def test_sideeffects_failure6(): with pytest.raises(ValueError): list(sideeffects([T(3), T(12), T(11)], raise_error_when_below10, 2))
def test_sideeffects_failure1(): l = [] with pytest.raises(_hf.FailIter.EXC_TYP, match=_hf.FailIter.EXC_MSG): sideeffects(_hf.FailIter(), l.append)
def test_sideeffects_normal8(): # useless side-effect assert list(sideeffects(toT(range(10)), return_None, 3)) == toT(range(10))
def test_sideeffects_normal6(): # generator l = [] assert list(sideeffects((i for i in [T(1), T(2)]), l.append, 2)) == [T(1), T(2)] assert l == [(T(1), T(2))]
def test_sideeffects_normal4(): l = [] assert list(sideeffects([T(1), T(2)], l.append, 2)) == [T(1), T(2)] assert l == [(T(1), T(2))]
def test_sideeffects_failure_setstate4(): # The length of the second argument must be equal to the "times". se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1) with pytest.raises(ValueError): se.__setstate__((1, (T(1), T(2))))
def test_sideeffects_failure_setstate3(): # The first argument must not be smaller than zero se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1) with pytest.raises(ValueError): se.__setstate__((-1, (T(1), )))
def test_sideeffects_failure_setstate2(): # The first argument must be smaller than the length of the second se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1) with pytest.raises(ValueError): se.__setstate__((1, (T(1), )))
def test_sideeffects_failure_setstate1(): # If times==0 then the second argument must be None se = sideeffects([T(1), T(2), T(3), T(4)], return_None) with pytest.raises(TypeError): se.__setstate__((0, ()))
def test_sideeffects_copy1(): _hf.iterator_copy(sideeffects(toT([1, 2, 3, 4]), return_None))
def test_sideeffects_failure8(): # Too few arguments with pytest.raises(TypeError): sideeffects()
def test_sideeffects_failure7(): # Test that a failing iterator doesn't raise a SystemError with pytest.raises(_hf.FailNext.EXC_TYP, match=_hf.FailNext.EXC_MSG): list(sideeffects(_hf.FailNext(), lambda x: x))
def test_sideeffects_empty4(): assert list(sideeffects([], return_None, 10)) == []
def test_sideeffects_normal3(): l = [] assert list(sideeffects([T(1), T(2)], l.append, 1)) == [T(1), T(2)] assert l == [(T(1), ), (T(2), )]
def test_sideeffects_failure_setstate6(): # If the second argument is None then the first argument must be zero se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 0) with pytest.raises(TypeError): se.__setstate__((1, None))
def test_sideeffects_normal5(): l = [] assert list(sideeffects([T(1), T(2), T(3)], l.append, times=2)) == [T(1), T(2), T(3)] assert l == [(T(1), T(2)), (T(3), )]
def test_sideeffects_failure_setstate7(): # The second argument must be a tuple or None se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 2) with pytest.raises(TypeError): se.__setstate__((1, [T(1), T(2)]))
def test_sideeffects_normal7(): # useless side-effect assert list(sideeffects([T(1), T(2)], return_None)) == [T(1), T(2)]
def test_sideeffects_failure_setstate9(): _hf.iterator_setstate_empty_fail( sideeffects([T(1), T(2), T(3), T(4)], return_None, 2))
def test_sideeffects_attribute1(): it = sideeffects(toT(range(10)), return_None) assert it.times == 0 assert it.func is return_None assert it.count == 0
def test_sideeffects_pickle6(protocol): suc = sideeffects([T(1), T(2), T(3), T(4)], return_None, 2) assert next(suc) == T(1) assert next(suc) == T(2) x = pickle.dumps(suc, protocol=protocol) assert list(pickle.loads(x)) == [T(3), T(4)]
def test_sideeffects_lengthhint1(): it = sideeffects([1, 2, 3, 4, 5, 6], return_None) _hf.check_lengthhint_iteration(it, 6)
def test_sideeffects_failure3(): with pytest.raises(ValueError): list(sideeffects([T(1), T(2), T(3)], raise_error_when_below10))