Пример #1
0
def test_ws_retrieve_data_on_input_ports():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_in_port(1, "in", 1)

    # non existing port
    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.get(10))

    # lonely input port without data
    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.get(1))

    # lonely input port with data
    ws.store_param(1, "param", 0)
    assert ws.get(1) == "param"

    # connected input port
    pg.connect(0, 1)
    ws = WorkflowState(pg)

    ws.store(0, "data")
    assert ws.get(1) == "data"
Пример #2
0
def test_evaluation_propagated_upstream():
    visited = []

    def func(txt):
        visited.append(txt)
        return txt

    pg = PortGraph()
    n = FuncNode(func)
    pg.add_actor(n, 0)
    pg.add_actor(n, 1)
    pg.connect(pg.out_port(0, 'txt'), pg.in_port(1, 'txt'))

    algo = BruteEvaluation(pg)

    ws = WorkflowState(pg)
    env = EvaluationEnvironment()
    ws.store_param(pg.in_port(0, 'txt'), "txt", 0)

    algo.eval(env, ws, 0)
    assert len(visited) == 1
    algo.eval(env, ws, 1)
    assert len(visited) == 2

    env.new_execution()
    algo.eval(env, ws, 1)
    assert len(visited) == 4
Пример #3
0
def test_ws_when_set_explicitly_for_params():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)

    ws = WorkflowState(pg)
    ws.store_param(0, "param", 10)
    assert ws.when(0) == 10
Пример #4
0
def test_ws_is_ready_for_evaluation():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    pg.add_out_port(0, "out", 1)
    pg.add_vertex(1)
    pg.add_out_port(1, "out", 2)
    pg.add_vertex(2)
    pg.add_in_port(2, "in", 3)
    pg.add_out_port(2, "out", 4)
    pg.connect(1, 3)
    pg.connect(2, 3)

    ws = WorkflowState(pg)
    assert not ws.is_ready_for_evaluation()

    ws.store(1, "data")
    assert not ws.is_ready_for_evaluation()

    ws.store_param(0, "param", 0)
    assert ws.is_ready_for_evaluation()
Пример #5
0
def test_lazy_do_not_reevaluate_node_if_same_execution():
    evaluated = []

    def func(txt):
        evaluated.append(txt)
        return txt

    pg = PortGraph()
    vid = pg.add_actor(FuncNode(func))
    assert pg.actor(vid).is_lazy()

    algo = LazyEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(pg.in_port(vid, 'txt'), 'toto', env.current_execution())

    algo.eval(env, ws)
    assert len(evaluated) == 1

    algo.eval_node(env, ws, vid)
    assert len(evaluated) == 1
Пример #6
0
def test_ws_store_param_only_on_lonely_input_ports():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    pg.add_out_port(0, "out", 1)
    pg.add_vertex(1)
    pg.add_in_port(1, "in", 2)
    pg.connect(1, 2)

    ws = WorkflowState(pg)

    assert_raises(UserWarning, lambda: ws.store_param(1, "param", 0))
    assert_raises(UserWarning, lambda: ws.store_param(2, "param", 0))
Пример #7
0
def test_lazy_always_reevaluate_non_lazy_nodes():
    evaluated = []

    def func(txt):
        evaluated.append(txt)
        return txt

    pg = PortGraph()
    vid = pg.add_actor(FuncNode(func))
    pg.actor(vid).set_lazy(False)

    algo = LazyEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(pg.in_port(vid, 'txt'), 'toto', env.current_execution())

    algo.eval(env, ws)
    assert len(evaluated) == 1

    env.new_execution()
    algo.eval(env, ws)
    assert len(evaluated) == 2
Пример #8
0
def test_evaluation_affect_output_to_right_ports():
    def func(a, b):
        c = a + b
        d = a * 2
        return c, d

    # simple order
    pg = PortGraph()
    n = FuncNode(func)
    pg.add_vertex(0)
    pg.add_in_port(0, 'a', 0)
    pg.add_in_port(0, 'b', 1)
    pg.add_out_port(0, 'c', 2)
    pg.add_out_port(0, 'd', 3)

    pg.set_actor(0, n)

    algo = BruteEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(0, 'a', 0)
    ws.store_param(1, 'b', 0)
    algo.eval(env, ws)

    assert ws.get(2) == 'ab'
    assert ws.get(3) == 'aa'

    # reverse input orders
    pg = PortGraph()
    n = FuncNode(func)
    pg.add_vertex(0)
    pg.add_in_port(0, 'b', 0)
    pg.add_in_port(0, 'a', 1)
    pg.add_out_port(0, 'c', 2)
    pg.add_out_port(0, 'd', 3)

    pg.set_actor(0, n)

    algo = BruteEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(0, 'a', 0)
    ws.store_param(1, 'b', 0)
    algo.eval(env, ws)

    assert ws.get(2) == 'ba'
    assert ws.get(3) == 'bb'

    # reverse output order
    pg = PortGraph()
    n = FuncNode(func)
    pg.add_vertex(0)
    pg.add_in_port(0, 'a', 0)
    pg.add_in_port(0, 'b', 1)
    pg.add_out_port(0, 'd', 2)
    pg.add_out_port(0, 'c', 3)

    pg.set_actor(0, n)

    algo = BruteEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(0, 'a', 0)
    ws.store_param(1, 'b', 0)
    algo.eval(env, ws)

    assert ws.get(3) == 'ab'
    assert ws.get(2) == 'aa'