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_clamp_lengthhint_failure2(): of_it = _hf.OverflowLengthHint(toT([1, 2, 3]), sys.maxsize + 1) it = clamp(of_it) with pytest.raises(OverflowError): operator.length_hint(it) with pytest.raises(OverflowError): list(it)
def test_clamp_lengthhint_failure1(): f_it = _hf.FailLengthHint(toT([1, 2, 3])) it = clamp(f_it) 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_clamp_normal4(): # both, inclusive assert list(clamp(toT(range(10)), low=T(2), high=T(7), inclusive=True)) == toT([3, 4, 5, 6])
def test_clamp_normal3(): # only high assert list(clamp(toT(range(10)), high=T(7))) == toT([0, 1, 2, 3, 4, 5, 6, 7])
def test_clamp_pickle4(protocol): # only high clmp = clamp(map(T, range(10)), high=T(7)) assert next(clmp) == T(0) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([1, 2, 3, 4, 5, 6, 7])
def test_clamp_failure3(): # Test that a failing iterator doesn't raise a SystemError with pytest.raises(_hf.FailNext.EXC_TYP, match=_hf.FailNext.EXC_MSG): next(clamp(_hf.FailNext()))
def test_clamp_failure1(): with pytest.raises(TypeError): list(clamp(toT(range(10)), T('a'), T(3)))
def test_clamp_normal9(): # no low/high (given as None) assert list(clamp(toT(range(10)), None, None)) == toT([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
def test_clamp_normal7(): # only high without remove assert list(clamp(toT(range(10)), high=T(7), remove=False)) == toT([0, 1, 2, 3, 4, 5, 6, 7, 7, 7])
def test_clamp_normal1(): assert list(clamp(toT(range(10)), T(2), T(7))) == toT([2, 3, 4, 5, 6, 7])
def test_clamp_lengthhint1(): # When remove=False we can determine the length-hint. it = clamp(toT(range(5)), low=T(2), high=T(5), remove=False) _hf.check_lengthhint_iteration(it, 5)
def test_clamp_pickle8(protocol): # only high but without remove clmp = clamp(map(T, range(10)), high=T(7), remove=False) assert next(clmp) == T(0) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([1, 2, 3, 4, 5, 6, 7, 7, 7])
def test_clamp_pickle7(protocol): # no low no high clmp = clamp(map(T, range(10))) assert next(clmp) == T(0) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([1, 2, 3, 4, 5, 6, 7, 8, 9])
def test_clamp_pickle6(protocol): # only low, with inclusive clmp = clamp(map(T, range(10)), T(2), inclusive=True) assert next(clmp) == T(3) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([4, 5, 6, 7, 8, 9])
def test_clamp_pickle5(protocol): # only high, with inclusive clmp = clamp(map(T, range(10)), high=T(7), inclusive=True) assert next(clmp) == T(0) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([1, 2, 3, 4, 5, 6])
def test_clamp_empty1(): assert list(clamp([], T(10), T(100))) == []
def test_clamp_normal5(): # no low/high assert list(clamp(toT(range(10)))) == toT([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
def test_clamp_normal6(): # only low without remove assert list(clamp(toT(range(10)), T(2), remove=False)) == (toT([2, 2, 2, 3, 4, 5, 6, 7, 8, 9]))
def test_clamp_lengthhint2(): # When low and high are not given we can determine the length-hint it = clamp(toT(range(5))) _hf.check_lengthhint_iteration(it, 5)
def test_clamp_normal8(): # both without remove assert list(clamp(toT(range(10)), low=T(2), high=T(7), remove=False)) == toT([2, 2, 2, 3, 4, 5, 6, 7, 7, 7])
def test_clamp_lengthhint3(): # Only works if "remove=False", otherwise the length-hint simply returns 0. it = clamp(toT(range(5)), low=T(2), high=T(5), remove=True) assert operator.length_hint(it) == 0
def test_clamp_attributes1(): it = clamp(toT(range(5)), T(1)) assert it.low == T(1) assert it.high is None assert it.remove assert not it.inclusive
def test_clamp_failure5(): # Too few arguments with pytest.raises(TypeError): clamp()
def test_clamp_failure2(): with pytest.raises(TypeError): list(clamp(map(T, range(10)), T(3), T('a')))
def test_clamp_pickle2(protocol): # inclusive clmp = clamp(map(T, range(10)), T(2), T(7), inclusive=True) assert next(clmp) == T(3) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([4, 5, 6])
def test_clamp_failure4(): with pytest.raises(_hf.FailIter.EXC_TYP, match=_hf.FailIter.EXC_MSG): clamp(_hf.FailIter())
def test_clamp_pickle3(protocol): # only low clmp = clamp(map(T, range(10)), T(2)) assert next(clmp) == T(2) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([3, 4, 5, 6, 7, 8, 9])
def test_clamp_normal2(): # only low assert list(clamp(toT(range(10)), T(2))) == toT([2, 3, 4, 5, 6, 7, 8, 9])
def test_clamp_pickle1(protocol): clmp = clamp(toT(range(10)), T(2), T(7)) assert next(clmp) == T(2) x = pickle.dumps(clmp, protocol=protocol) assert list(pickle.loads(x)) == toT([3, 4, 5, 6, 7])