def test_iterexcept_pickle4(protocol):
    dct = {}
    first = partial(dct.setdefault, T('a'), T(10))
    ie = iter_except(dct.popitem, KeyError, first)
    assert next(ie) == T(10)
    x = pickle.dumps(ie, protocol=protocol)
    assert list(pickle.loads(x)) == [(T('a'), T(10))]
Ejemplo 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()
def test_iterexcept_first():
    d = {}

    def insert():
        d[T('a')] = T(10)

    exp_out = [None, (T('a'), T(10))]
    assert list(iter_except(d.popitem, KeyError, insert)) == exp_out
def test_iterexcept_pickle2(protocol):
    dct = {T('a'): T(10)}
    ie = iter_except(dct.popitem, KeyError, None)
    x = pickle.dumps(ie, protocol=protocol)
    assert list(pickle.loads(x)) == [(T('a'), T(10))]
def test_iterexcept_copy1():
    dct = {T('a'): T(10)}
    _hf.iterator_copy(iter_except(dct.popitem, KeyError))
def test_iterexcept_failure2():
    # too few arguments
    with pytest.raises(TypeError):
        iter_except()
def test_iterexcept_failure1():
    # wrong exception
    with pytest.raises(KeyError):
        list(iter_except(({T('a'): T(10)}).popitem, ValueError))
def test_iterexcept_attributes2():
    it = iter_except(list.append, ValueError, list)
    assert it.func is list.append
    assert it.exception is ValueError
    assert it.first is list
def test_iterexcept_attributes1():
    it = iter_except(list.append, ValueError)
    assert it.func is list.append
    assert it.exception is ValueError
    with pytest.raises(AttributeError):
        it.first
def test_iterexcept_normal2():
    # None as "first" argument is equivalent to not passing in a "first".
    dct = {T('a'): T(10)}
    assert list(iter_except(dct.popitem, KeyError, None)) == [(T('a'), T(10))]
def test_iterexcept_normal1():
    dct = {T('a'): T(10)}
    assert list(iter_except(dct.popitem, KeyError)) == [(T('a'), T(10))]