Esempio n. 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"
Esempio n. 2
0
def test_ws_can_not_store_data_on_input_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    ws = WorkflowState(pg)

    assert_raises(UserWarning, lambda: ws.store(0, "data"))
Esempio n. 3
0
def test_portgraph_connected_ports():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: tuple(pg.connected_ports(0)))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    for pid in (pid1, pid2, pid3, pid4):
        assert len(tuple(pg.connected_ports(pid))) == 0

    pg.connect(pid3, pid1)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert tuple(pg.connected_ports(pid1)) == (pid3,)
    for pid in (pid2, pid4):
        assert len(tuple(pg.connected_ports(pid))) == 0

    pg.connect(pid4, pid1)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert tuple(pg.connected_ports(pid4)) == (pid1,)
    assert sorted(pg.connected_ports(pid1)) == sorted((pid3, pid4))
    assert len(tuple(pg.connected_ports(pid2))) == 0

    pg.connect(pid4, pid2)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert sorted(pg.connected_ports(pid4)) == sorted((pid1, pid2))
    assert sorted(pg.connected_ports(pid1)) == sorted((pid3, pid4))
    assert tuple(pg.connected_ports(pid2)) == (pid4,)
def test_portgraph_connected_ports():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: tuple(pg.connected_ports(0)))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    for pid in (pid1, pid2, pid3, pid4):
        assert len(tuple(pg.connected_ports(pid))) == 0

    pg.connect(pid3, pid1)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert tuple(pg.connected_ports(pid1)) == (pid3,)
    for pid in (pid2, pid4):
        assert len(tuple(pg.connected_ports(pid))) == 0

    pg.connect(pid4, pid1)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert tuple(pg.connected_ports(pid4)) == (pid1,)
    assert sorted(pg.connected_ports(pid1)) == sorted((pid3, pid4))
    assert len(tuple(pg.connected_ports(pid2))) == 0

    pg.connect(pid4, pid2)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert sorted(pg.connected_ports(pid4)) == sorted((pid1, pid2))
    assert sorted(pg.connected_ports(pid1)) == sorted((pid3, pid4))
    assert tuple(pg.connected_ports(pid2)) == (pid4,)
def portgraph_nb_connections():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.nb_connections(0))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    for pid in (pid1, pid2, pid3, pid4):
        assert pg.nb_connections(pid) == 0

    pg.connect(pid3, pid1)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid1) == 1
    assert pg.nb_connections(pid2) == 0
    assert pg.nb_connections(pid4) == 0

    pg.connect(pid4, pid1)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid4) == 1
    assert pg.nb_connections(pid1) == 2
    assert pg.nb_connections(pid2) == 0

    pg.connect(pid4, pid2)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid4) == 2
    assert pg.nb_connections(pid1) == 2
    assert pg.nb_connections(pid2) == 1
def test_portgraph_connected_edges():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: tuple(pg.connected_edges(0)))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    # test vertices and ports are created without connections
    for pid in (pid1, pid2, pid3, pid4):
        assert len(tuple(pg.connected_edges(pid))) == 0

    eid1 = pg.connect(pid3, pid1)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert tuple(pg.connected_edges(pid1)) == (eid1,)
    for pid in (pid2, pid4):
        assert len(tuple(pg.connected_edges(pid))) == 0

    eid2 = pg.connect(pid4, pid1)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert tuple(pg.connected_edges(pid4)) == (eid2,)
    assert sorted(pg.connected_edges(pid1)) == sorted((eid1, eid2))
    assert len(tuple(pg.connected_edges(pid2))) == 0

    eid3 = pg.connect(pid4, pid2)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert sorted(pg.connected_edges(pid4)) == sorted((eid2, eid3))
    assert sorted(pg.connected_edges(pid1)) == sorted((eid1, eid2))
    assert tuple(pg.connected_edges(pid2)) == (eid3,)
Esempio n. 7
0
def portgraph_nb_connections():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.nb_connections(0))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    for pid in (pid1, pid2, pid3, pid4):
        assert pg.nb_connections(pid) == 0

    pg.connect(pid3, pid1)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid1) == 1
    assert pg.nb_connections(pid2) == 0
    assert pg.nb_connections(pid4) == 0

    pg.connect(pid4, pid1)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid4) == 1
    assert pg.nb_connections(pid1) == 2
    assert pg.nb_connections(pid2) == 0

    pg.connect(pid4, pid2)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid4) == 2
    assert pg.nb_connections(pid1) == 2
    assert pg.nb_connections(pid2) == 1
Esempio n. 8
0
def test_ws_when_is_none_for_non_evaluated_output_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)

    ws = WorkflowState(pg)
    assert ws.when(0) is None
Esempio n. 9
0
def test_ws_when_raise_key_error_for_unset_param():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)

    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.when(0))
Esempio n. 10
0
def test_portgraph_connected_edges():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: tuple(pg.connected_edges(0)))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    # test vertices and ports are created without connections
    for pid in (pid1, pid2, pid3, pid4):
        assert len(tuple(pg.connected_edges(pid))) == 0

    eid1 = pg.connect(pid3, pid1)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert tuple(pg.connected_edges(pid1)) == (eid1,)
    for pid in (pid2, pid4):
        assert len(tuple(pg.connected_edges(pid))) == 0

    eid2 = pg.connect(pid4, pid1)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert tuple(pg.connected_edges(pid4)) == (eid2,)
    assert sorted(pg.connected_edges(pid1)) == sorted((eid1, eid2))
    assert len(tuple(pg.connected_edges(pid2))) == 0

    eid3 = pg.connect(pid4, pid2)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert sorted(pg.connected_edges(pid4)) == sorted((eid2, eid3))
    assert sorted(pg.connected_edges(pid1)) == sorted((eid1, eid2))
    assert tuple(pg.connected_edges(pid2)) == (eid3,)
Esempio n. 11
0
def test_ws_when_is_none_on_creation():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    pg.add_out_port(0, "out", 1)

    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.when(10))
Esempio n. 12
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
Esempio n. 13
0
def test_ws_nodes_not_evaluated_on_creation():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_vertex(1)

    ws = WorkflowState(pg)
    assert ws.last_evaluation(0) is None
    assert ws.last_evaluation(1) is None
Esempio n. 14
0
def test_ws_when_is_last_evaluation_for_output_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)

    ws = WorkflowState(pg)
    ws.set_last_evaluation(0, 1)
    assert ws.when(0) == 1
Esempio n. 15
0
def test_ws_nodes_last_evaluation():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_vertex(1)

    ws = WorkflowState(pg)
    ws.set_last_evaluation(0, 1)
    assert ws.last_evaluation(0) == 1
    assert ws.last_evaluation(1) is None
Esempio n. 16
0
def test_portgraph_add_vertex():
    pg = PortGraph()

    vid = pg.add_vertex()
    assert pg.nb_vertices() == 1
    assert_raises(InvalidVertex, lambda: pg.add_vertex(vid))

    assert len(tuple(pg.ports(vid))) == 0
    assert pg.actor(vid) is None
Esempio n. 17
0
def test_portgraph_add_vertex():
    pg = PortGraph()

    vid = pg.add_vertex()
    assert pg.nb_vertices() == 1
    assert_raises(InvalidVertex, lambda: pg.add_vertex(vid))

    assert len(tuple(pg.ports(vid))) == 0
    assert pg.actor(vid) is None
Esempio n. 18
0
def test_evaluation_new_require_evaluation():
    pg = PortGraph()
    pg.add_vertex(0)

    algo = BruteEvaluation(pg)
    assert id(algo.portgraph()) == id(pg)

    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    assert algo.requires_evaluation(env, ws)
Esempio n. 19
0
def test_ws_retrieve_stored_data_on_output_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    ws = WorkflowState(pg)

    ws.store(0, "data")
    assert_raises(KeyError, lambda: ws.get(1))

    assert ws.get(0) == "data"
Esempio n. 20
0
def test_ws_is_created_empty():
    pg = PortGraph()
    ws = WorkflowState(pg)
    assert len(tuple(ws.items())) == 0
    assert id(ws.portgraph()) == id(pg)

    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    pg.add_out_port(0, "out", 1)

    ws = WorkflowState(pg)
    assert len(tuple(ws.items())) == 0
Esempio n. 21
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))
Esempio n. 22
0
def test_ws_sub_ready_for_evaluation_if_no_input_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_in_port(1, "in", 1)
    pg.connect(0, 1)

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

    subpg = get_upstream_subportgraph(pg, 1)
    subws = WorkflowState(subpg)
    assert subws.is_ready_for_evaluation()
Esempio n. 23
0
def test_portgraph_add_actor():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    actor = Node()
    keys = {"toto", 1, "titi"}
    for key in keys:
        actor.add_input(key, "descr")
        actor.add_output(key, "descr")

    # bad actor
    assert_raises(AttributeError, lambda: pg.add_actor(None))
    assert len(pg) == 1
    assert_raises(AttributeError, lambda: pg.add_actor(None, vid1 + 1))
    assert len(pg) == 1
    # vertex id already used
    assert_raises(InvalidVertex, lambda: pg.add_actor(actor, vid1))
    assert len(pg) == 1

    for key in actor.inputs():
        pg.add_in_port(vid1, key)

    for key in actor.outputs():
        pg.add_out_port(vid1, key)

    pg.set_actor(vid1, actor)
    # vertex id already used
    assert_raises(InvalidVertex, lambda: pg.add_actor(actor, vid1))
    assert len(pg) == 1

    vid2 = pg.add_actor(actor)
    assert pg.actor(vid2) == actor
    assert set(actor.inputs()) == keys
    assert set(pg.local_id(pid) for pid in pg.in_ports(vid2)) == keys
    assert set(actor.outputs()) == keys
    assert set(pg.local_id(pid) for pid in pg.out_ports(vid2)) == keys
Esempio n. 24
0
def test_portgraph_connect():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    # invalid ports
    assert_raises(InvalidPort, lambda: pg.connect(0, 1))
    # invalid source port
    pid1 = pg.add_in_port(vid1, "in")
    assert_raises(InvalidPort, lambda: pg.connect(pid1 + 1, pid1))
    # invalid out port
    pid2 = pg.add_out_port(vid2, "out")
    assert_raises(InvalidPort, lambda: pg.connect(pid2, pid1 + pid2 + 1))
    # edge connection from in to out raise error
    assert_raises(InvalidPort, lambda: pg.connect(pid1, pid2))

    eid = pg.connect(pid2, pid1)
    assert pg.source_port(eid) == pid2
    assert pg.target_port(eid) == pid1
    assert tuple(pg.connected_edges(pid1)) == (eid,)
    assert tuple(pg.connected_edges(pid2)) == (eid,)
    assert pid1 in pg.connected_ports(pid2)
    assert pid2 in pg.connected_ports(pid1)

    # can not duplicate edge
    assert_raises(InvalidEdge, lambda: pg.connect(pid2, pid1, eid))
Esempio n. 25
0
def test_portgraph_set_actor():
    pg = PortGraph()
    assert_raises(InvalidVertex, lambda: pg.set_actor(0, None))

    actor = Node()
    for key in ("toto", 1, "titi"):
        actor.add_input(key, "descr")
        actor.add_output(key, "descr")

    assert_raises(InvalidVertex, lambda: pg.set_actor(0, actor))

    vid = pg.add_vertex()
    pg.set_actor(vid, None)
    assert pg.actor(vid) is None
    assert_raises(InvalidPort, lambda: pg.set_actor(vid, actor))

    for key in actor.inputs():
        pg.add_in_port(vid, key)

    assert_raises(InvalidPort, lambda: pg.set_actor(vid, actor))

    for key in actor.outputs():
        pg.add_out_port(vid, key)

    pg.set_actor(vid, actor)
    assert pg.actor(vid) == actor

    pg.set_actor(vid, None)
    assert pg.actor(vid) is None
Esempio n. 26
0
def test_portgraph_add_actor():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    actor = Node()
    keys = {"toto", 1, "titi"}
    for key in keys:
        actor.add_input(key, "descr")
        actor.add_output(key, "descr")

    # bad actor
    assert_raises(AttributeError, lambda: pg.add_actor(None))
    assert len(pg) == 1
    assert_raises(AttributeError, lambda: pg.add_actor(None, vid1 + 1))
    assert len(pg) == 1
    # vertex id already used
    assert_raises(InvalidVertex, lambda: pg.add_actor(actor, vid1))
    assert len(pg) == 1

    for key in actor.inputs():
        pg.add_in_port(vid1, key)

    for key in actor.outputs():
        pg.add_out_port(vid1, key)

    pg.set_actor(vid1, actor)
    # vertex id already used
    assert_raises(InvalidVertex, lambda: pg.add_actor(actor, vid1))
    assert len(pg) == 1

    vid2 = pg.add_actor(actor)
    assert pg.actor(vid2) == actor
    assert set(actor.inputs()) == keys
    assert set(pg.local_id(pid) for pid in pg.in_ports(vid2)) == keys
    assert set(actor.outputs()) == keys
    assert set(pg.local_id(pid) for pid in pg.out_ports(vid2)) == keys
Esempio n. 27
0
def test_evaluation_fail_if_port_mismatch_outputs():
    def func():
        return 1, 2

    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, 'res', 0)
    n = RawFuncNode(func)
    n.add_output('res', "descr")
    pg.set_actor(0, n)

    algo = BruteEvaluation(pg)

    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    assert_raises(EvaluationError, lambda: algo.eval(env, ws))
Esempio n. 28
0
def test_portgraph_connect():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    # invalid ports
    assert_raises(InvalidPort, lambda: pg.connect(0, 1))
    # invalid source port
    pid1 = pg.add_in_port(vid1, "in")
    assert_raises(InvalidPort, lambda: pg.connect(pid1 + 1, pid1))
    # invalid out port
    pid2 = pg.add_out_port(vid2, "out")
    assert_raises(InvalidPort, lambda: pg.connect(pid2, pid1 + pid2 + 1))
    # edge connection from in to out raise error
    assert_raises(InvalidPort, lambda: pg.connect(pid1, pid2))

    eid = pg.connect(pid2, pid1)
    assert pg.source_port(eid) == pid2
    assert pg.target_port(eid) == pid1
    assert tuple(pg.connected_edges(pid1)) == (eid,)
    assert tuple(pg.connected_edges(pid2)) == (eid,)
    assert pid1 in pg.connected_ports(pid2)
    assert pid2 in pg.connected_ports(pid1)

    # can not duplicate edge
    assert_raises(InvalidEdge, lambda: pg.connect(pid2, pid1, eid))
Esempio n. 29
0
def test_portgraph_set_actor():
    pg = PortGraph()
    assert_raises(InvalidVertex, lambda: pg.set_actor(0, None))

    actor = Node()
    for key in ("toto", 1, "titi"):
        actor.add_input(key, "descr")
        actor.add_output(key, "descr")

    assert_raises(InvalidVertex, lambda: pg.set_actor(0, actor))

    vid = pg.add_vertex()
    pg.set_actor(vid, None)
    assert pg.actor(vid) is None
    assert_raises(InvalidPort, lambda: pg.set_actor(vid, actor))

    for key in actor.inputs():
        pg.add_in_port(vid, key)

    assert_raises(InvalidPort, lambda: pg.set_actor(vid, actor))

    for key in actor.outputs():
        pg.add_out_port(vid, key)

    pg.set_actor(vid, actor)
    assert pg.actor(vid) == actor

    pg.set_actor(vid, None)
    assert pg.actor(vid) is None
Esempio n. 30
0
def test_portgraph_vertex():
    pg = PortGraph()

    assert_raises(InvalidPort, lambda: pg.vertex(0))

    vid = pg.add_vertex()
    pid1 = pg.add_in_port(vid, 0)
    pid2 = pg.add_out_port(vid, 0)
    assert pg.vertex(pid1) == vid
    assert pg.vertex(pid2) == vid
Esempio n. 31
0
def test_portgraph_vertex():
    pg = PortGraph()

    assert_raises(InvalidPort, lambda: pg.vertex(0))

    vid = pg.add_vertex()
    pid1 = pg.add_in_port(vid, 0)
    pid2 = pg.add_out_port(vid, 0)
    assert pg.vertex(pid1) == vid
    assert pg.vertex(pid2) == vid
Esempio n. 32
0
def test_portgraph_local_id():
    pg = PortGraph()
    vid = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.local_id(0))

    for lpid in (0, 1, "a", None):
        pid = pg.add_in_port(vid, lpid)
        assert pg.local_id(pid) == lpid
        pid = pg.add_out_port(vid, lpid)
        assert pg.local_id(pid) == lpid
Esempio n. 33
0
def test_portgraph_local_id():
    pg = PortGraph()
    vid = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.local_id(0))

    for lpid in (0, 1, "a", None):
        pid = pg.add_in_port(vid, lpid)
        assert pg.local_id(pid) == lpid
        pid = pg.add_out_port(vid, lpid)
        assert pg.local_id(pid) == lpid
Esempio n. 34
0
def test_portgraph_is_out_port():
    pg = PortGraph()
    vid = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.is_out_port(None))
    assert_raises(InvalidPort, lambda: pg.is_out_port(0))

    pid = pg.add_out_port(vid, "out")
    assert_raises(InvalidPort, lambda: pg.is_out_port(pid + 1))
    assert pg.is_out_port(pid)

    pid = pg.add_in_port(vid, "in")
    assert not pg.is_out_port(pid)
Esempio n. 35
0
def test_portgraph_is_out_port():
    pg = PortGraph()
    vid = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.is_out_port(None))
    assert_raises(InvalidPort, lambda: pg.is_out_port(0))

    pid = pg.add_out_port(vid, "out")
    assert_raises(InvalidPort, lambda: pg.is_out_port(pid + 1))
    assert pg.is_out_port(pid)

    pid = pg.add_in_port(vid, "in")
    assert not pg.is_out_port(pid)
Esempio n. 36
0
def test_portgraph_big():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    pid11 = pg.add_out_port(vid1, "out")
    vid2 = pg.add_vertex()
    pid21 = pg.add_out_port(vid2, "out")

    vid3 = pg.add_vertex()
    pid31 = pg.add_in_port(vid3, "in1")
    pid32 = pg.add_in_port(vid3, "in2")
    pid33 = pg.add_out_port(vid3, "res")

    vid4 = pg.add_vertex()
    pid41 = pg.add_in_port(vid4, "in")

    eid1 = pg.connect(pid11, pid31)
    eid2 = pg.connect(pid21, pid32)
    pg.connect(pid33, pid41)

    assert pg.source_port(eid1) == pid11
    assert pg.target_port(eid2) == pid32
    assert set(pg.out_ports(vid1)) == {pid11}
    assert set(pg.in_ports(vid3)) == {pid31, pid32}
    assert set(pg.ports(vid3)) == {pid31, pid32, pid33}
    assert pg.is_in_port(pid31)
    assert pg.is_out_port(pid11)
    assert pg.vertex(pid11) == vid1
    assert set(pg.connected_ports(pid11)) == {pid31}
    assert set(pg.connected_edges(pid21)) == {eid2}
    assert pg.out_port(vid1, "out") == pid11
    assert pg.in_port(vid3, "in1") == pid31

    assert_raises(InvalidPort, lambda: pg.connect(pid11, pid33))

    pg.remove_port(pid33)
    assert set(pg.connected_ports(pid41)) == set()
    assert set(pg.out_edges(vid3)) == set()
    assert_raises(InvalidPort, lambda: pg.is_in_port(pid33))
Esempio n. 37
0
def test_portgraph_big():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    pid11 = pg.add_out_port(vid1, "out")
    vid2 = pg.add_vertex()
    pid21 = pg.add_out_port(vid2, "out")

    vid3 = pg.add_vertex()
    pid31 = pg.add_in_port(vid3, "in1")
    pid32 = pg.add_in_port(vid3, "in2")
    pid33 = pg.add_out_port(vid3, "res")

    vid4 = pg.add_vertex()
    pid41 = pg.add_in_port(vid4, "in")

    eid1 = pg.connect(pid11, pid31)
    eid2 = pg.connect(pid21, pid32)
    pg.connect(pid33, pid41)

    assert pg.source_port(eid1) == pid11
    assert pg.target_port(eid2) == pid32
    assert set(pg.out_ports(vid1)) == {pid11}
    assert set(pg.in_ports(vid3)) == {pid31, pid32}
    assert set(pg.ports(vid3)) == {pid31, pid32, pid33}
    assert pg.is_in_port(pid31)
    assert pg.is_out_port(pid11)
    assert pg.vertex(pid11) == vid1
    assert set(pg.connected_ports(pid11)) == {pid31}
    assert set(pg.connected_edges(pid21)) == {eid2}
    assert pg.out_port(vid1, "out") == pid11
    assert pg.in_port(vid3, "in1") == pid31

    assert_raises(InvalidPort, lambda: pg.connect(pid11, pid33))

    pg.remove_port(pid33)
    assert set(pg.connected_ports(pid41)) == set()
    assert set(pg.out_edges(vid3)) == set()
    assert_raises(InvalidPort, lambda: pg.is_in_port(pid33))
Esempio n. 38
0
def test_portgraph_out_port():
    pg = PortGraph()
    assert_raises(InvalidVertex, lambda: pg.out_port(0, None))

    vid = pg.add_vertex()
    assert_raises(InvalidPort, lambda: pg.out_port(vid, None))

    pg.add_in_port(vid, "toto")
    assert_raises(InvalidPort, lambda: pg.out_port(vid, None))

    for lpid in [0, 1, "a", None]:
        assert_raises(InvalidPort, lambda: pg.out_port(vid, "toto"))
        pid = pg.add_out_port(vid, lpid)
        assert pg.out_port(vid, lpid) == pid
Esempio n. 39
0
def test_portgraph_out_port():
    pg = PortGraph()
    assert_raises(InvalidVertex, lambda: pg.out_port(0, None))

    vid = pg.add_vertex()
    assert_raises(InvalidPort, lambda: pg.out_port(vid, None))

    pg.add_in_port(vid, "toto")
    assert_raises(InvalidPort, lambda: pg.out_port(vid, None))

    for lpid in [0, 1, "a", None]:
        assert_raises(InvalidPort, lambda: pg.out_port(vid, "toto"))
        pid = pg.add_out_port(vid, lpid)
        assert pg.out_port(vid, lpid) == pid
Esempio n. 40
0
def test_portgraph_clear():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    pid1 = pg.add_in_port(vid1, "in")
    pid2 = pg.add_out_port(vid2, "out")

    pg.connect(pid2, pid1)

    pg.clear()

    assert pg.nb_vertices() == 0
    assert pg.nb_edges() == 0
    assert len(tuple(pg.ports())) == 0
Esempio n. 41
0
def test_ws_dos_not_allow_graph_editing():
    pg = PortGraph()
    ws = WorkflowState(pg)

    assert ws.portgraph_still_valid()
    pg.add_vertex(0)
    assert not ws.portgraph_still_valid()

    ws = WorkflowState(pg)
    assert ws.portgraph_still_valid()
    pg.add_out_port(0, "out", 0)
    assert not ws.portgraph_still_valid()

    pg.add_vertex(1)
    pg.add_in_port(1, "in", 1)
    ws = WorkflowState(pg)
    assert ws.portgraph_still_valid()
    pg.connect(0, 1)
    assert not ws.portgraph_still_valid()

    ws = WorkflowState(pg)
    assert ws.portgraph_still_valid()
    pg.remove_port(0)
    assert not ws.portgraph_still_valid()
def get_pg():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_out_port(1, "out", 1)

    pg.add_vertex(2)
    pg.add_in_port(2, "in1", 2)
    pg.add_in_port(2, "in2", 3)
    pg.add_out_port(2, "res", 4)

    pg.add_vertex(3)
    pg.add_in_port(3, "in", 5)

    pg.add_vertex(4)
    pg.add_out_port(4, "out", 6)

    pg.connect(0, 2, 0)
    pg.connect(1, 3, 1)
    pg.connect(4, 5, 2)
    pg.connect(6, 3, 3)

    return pg
Esempio n. 43
0
def test_portgraph_add_out_port():
    pg = PortGraph()
    assert_raises(InvalidVertex, lambda: pg.add_out_port(0, "toto"))

    vid = pg.add_vertex()
    pid = pg.add_out_port(vid, "port")

    # raise error if reuse same global port id
    assert_raises(IndexError, lambda: pg.add_out_port(vid, "toto", pid))
    # raise error if reuse same local port id
    assert_raises(InvalidPort, lambda: pg.add_out_port(vid, "port"))

    assert tuple(pg.out_ports(vid)) == (pid,)
    assert pg.local_id(pid) == "port"
    assert pg.out_port(vid, "port") == pid
def get_pg():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_out_port(1, "out", 1)

    pg.add_vertex(2)
    pg.add_in_port(2, "in1", 2)
    pg.add_in_port(2, "in2", 3)
    pg.add_out_port(2, "res", 4)

    pg.add_vertex(3)
    pg.add_in_port(3, "in", 5)

    pg.add_vertex(4)
    pg.add_out_port(4, "out", 6)

    pg.connect(0, 2, 0)
    pg.connect(1, 3, 1)
    pg.connect(4, 5, 2)
    pg.connect(6, 3, 3)

    return pg
Esempio n. 45
0
def test_portgraph_clear():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    pid1 = pg.add_in_port(vid1, "in")
    pid2 = pg.add_out_port(vid2, "out")

    pg.connect(pid2, pid1)

    pg.clear()

    assert pg.nb_vertices() == 0
    assert pg.nb_edges() == 0
    assert len(tuple(pg.ports())) == 0