Beispiel #1
0
def test_assert_with_dependencies(message):
    with pf.Graph() as graph:
        x = pf.placeholder(name='x')
        if message:
            assertion = pf.assert_(x < 10, message, 10, x)
        else:
            assertion = pf.assert_(x < 10)
        with pf.control_dependencies([assertion]):
            y = 2 * x

    assert len(y.dependencies) == 1
    assert graph(y, x=9) == 18
    with pytest.raises(AssertionError) as exc_info:
        graph(y, x=11)

    if message:
        exc_info.match(message % (10, 11))
Beispiel #2
0
def workers(broker):
    with pf.Graph() as graph:
        x = pf.placeholder('x')
        y = pf.placeholder('y')
        sleep = pf.func_op(time.sleep, pf.func_op(random.uniform, 0, .1))
        with pf.control_dependencies([sleep]):
            (x / y).set_name('z')
        # Can't pickle entire modules
        pf.constant(pf).set_name('not_pickleable')

    # Create multiple workers
    _workers = []
    while len(_workers) < 10:
        worker = pfmq.Worker.from_graph(graph, broker.backend_address)
        worker.run_async()
        _workers.append(worker)

    yield _workers

    # Shut down all the workers
    for worker in _workers:
        worker.cancel()