Example #1
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
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
Example #3
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
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
Example #5
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 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