コード例 #1
0
def test_packed_failure6():
    # function raised an Exception
    def failingfunc(a, b):
        raise ValueError('bad func')

    with pytest.raises(ValueError, match='bad func'):
        packed(failingfunc)((1, 2))
コード例 #2
0
def _chk_path_locks(start: object, processor: DiGraph,
                    path_locks: MutableMapping[object, _SatInfo],
                    capability: object) -> None:
    """Check if paths from the given start unit contains multiple locks.

    `start` is the starting unit of paths to check.
    `processor` is the processor containing the start unit.
    `path_locks` are the map from a unit to the information of the path
                 with maximum locks.
    `capability` is the capability of lock paths under consideration.
    The function raises a PathLockError if any paths originating from
    the given unit have multiple locks.

    """
    succ_lst = tuple(processor.successors(start))
    # because pylint can't detect packed as a member of
    # iteration_utilities
    # pylint: disable=no-member
    sat_params = map(
        iteration_utilities.packed(
            _PathLockCalc(processor.nodes[start], succ_lst, capability, start,
                          path_locks).calc_lock),
        [(units.UNIT_RLOCK_KEY, _PathDescriptor.make_read_desc),
         (units.UNIT_WLOCK_KEY, _PathDescriptor.make_write_desc)])
    # pylint: disable=no-member
    path_locks[start] = _SatInfo(*sat_params)
コード例 #3
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()
コード例 #4
0
ファイル: day15.py プロジェクト: N8Brooks/aoc_py
def count(a_gen, b_gen, sample):
    def valid(a, b):
        return a & BITS == b & BITS

    return count_items(islice(zip(a_gen, b_gen), sample), packed(valid))
コード例 #5
0
def test_packed_failure4():
    # too many arguments when calling the instance
    with pytest.raises(TypeError):
        packed(operator.eq)(1, 2)
コード例 #6
0
def test_packed_failure5():
    # arguments for calling the instance are not convertible to tuple
    with pytest.raises(TypeError):
        packed(operator.eq)(1)
コード例 #7
0
def test_packed_failure1():
    # too many arguments when creating an instance
    with pytest.raises(TypeError):
        packed(1, 2)
コード例 #8
0
def test_packed_failure2():
    # too few arguments when creating an instance
    with pytest.raises(TypeError):
        packed()
コード例 #9
0
def test_packed_normal_more_than_6(kind):
    t6 = packed(_t6)
    inp = kind([T(1), T(2), T(3), T(4), T(5), T(6)])
    assert t6(inp) == (T(1), T(2), T(3), T(4), T(5), T(6))
コード例 #10
0
def test_packed_normal_more_than_6_with_kwargs(kind):
    t6 = packed(_t6)
    inp = kind([T(1), T(2), T(3), T(4)])
    assert t6(inp, e=T(5), f=T(6)) == (T(1), T(2), T(3), T(4), T(5), T(6))
コード例 #11
0
def test_packed_normal_with_kwargs(kind):
    t3 = packed(_t3)
    inp = kind([T(1), T(2)])
    assert t3(inp, c=T(3)) == (T(1), T(2), T(3))
コード例 #12
0
def test_packed_normal(kind):
    eq = packed(operator.eq)
    assert eq(kind([T(1), T(1)]))
    assert not eq(kind([T(1), T(2)]))
コード例 #13
0
def test_packed_attributes1():
    x = packed(int)
    assert x.func is int
コード例 #14
0
def test_packed_repr1():
    x = packed(int)
    r = repr(x)
    assert 'packed' in r
    assert 'int' in r
コード例 #15
0
def test_packed_pickle1(protocol):
    eq = packed(operator.eq)
    x = pickle.dumps(eq, protocol=protocol)
    assert pickle.loads(x)((T(1), T(1)))
    assert not pickle.loads(x)((T(1), T(2)))