Exemplo n.º 1
0
def test_tabulate_failure3():
    tab = tabulate(iteration_utilities.return_identity, T(0))
    # Fail once while incrementing, this will set cnt to NULL
    with pytest.raises(TypeError):
        next(tab)
    with pytest.raises(StopIteration):
        next(tab)
Exemplo n.º 2
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()
Exemplo n.º 3
0
def test_tabulate_attributes1():
    it = tabulate(T)
    assert it.func is T
    assert it.current == 0

    next(it)

    assert it.current == 1
Exemplo n.º 4
0
def test_tabulate_failure1():
    class T:
        def __init__(self, val):
            self.val = val

        def __truediv__(self, other):
            return self.__class__(self.val / other.val)

    # Function call fails
    with pytest.raises(ZeroDivisionError):
        next(tabulate(lambda x: T(1) / x, T(0)))
Exemplo n.º 5
0
def test_tabulate_pickle3(protocol):
    rr = tabulate(T)
    x = pickle.dumps(rr, protocol=protocol)
    assert next(pickle.loads(x)) == T(0)
Exemplo n.º 6
0
def test_tabulate_pickle2(protocol):
    rr = tabulate(T, 2)
    assert next(rr) == T(2)
    x = pickle.dumps(rr, protocol=protocol)
    assert next(pickle.loads(x)) == T(3)
Exemplo n.º 7
0
def test_tabulate_copy1():
    _hf.iterator_copy(tabulate(T))
Exemplo n.º 8
0
def test_tabulate_failure4():
    # Too few arguments
    with pytest.raises(TypeError):
        tabulate()
Exemplo n.º 9
0
def test_tabulate_failure2():
    # incrementing with one fails
    with pytest.raises(TypeError):
        next(tabulate(iteration_utilities.return_identity, T(0.5)))
Exemplo n.º 10
0
def test_tabulate_normal2():
    assert list(getitem(tabulate(T), stop=5)) == [T(0), T(1), T(2), T(3), T(4)]
Exemplo n.º 11
0
def test_tabulate_normal1():
    assert list(getitem(tabulate(lambda x: x, T2(0)),
                        stop=5)) == [T2(0), T2(1),
                                     T2(2), T2(3),
                                     T2(4)]