Ejemplo n.º 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
Ejemplo n.º 2
0
def test_node_port_type():
    n = Node()
    n.add_input("in", "IInt")
    n.add_output("out", "IFloat")

    assert_raises(KeyError, lambda: n.input("toto"))
    assert_raises(KeyError, lambda: n.output("toto"))

    assert n.input("in").type == "IInt"
    assert n.output("out").type == "IFloat"
Ejemplo n.º 3
0
def test_node_port_descr():
    n = Node()
    n.add_input(1, descr="titi")
    n.add_output(2, descr="titi")

    assert n.input(1).descr == "titi"
    assert_raises(KeyError, lambda: n.input("toto"))

    assert n.output(2).descr == "titi"
    assert_raises(KeyError, lambda: n.output(1))
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_node_caption():
    n = Node()
    assert n.caption() == "caption"

    n.set_caption("toto")
    assert n.caption() == "toto"
    n.set_caption(1)
    assert n.caption() == "1"
Ejemplo n.º 6
0
def test_node_port_type():
    n = Node()
    n.add_input("in", "IInt")
    n.add_output("out", "IFloat")

    assert_raises(KeyError, lambda: n.input("toto"))
    assert_raises(KeyError, lambda: n.output("toto"))

    assert n.input("in").type == "IInt"
    assert n.output("out").type == "IFloat"
Ejemplo n.º 7
0
def test_node_port_descr():
    n = Node()
    n.add_input(1, descr="titi")
    n.add_output(2, descr="titi")

    assert n.input(1).descr == "titi"
    assert_raises(KeyError, lambda: n.input("toto"))

    assert n.output(2).descr == "titi"
    assert_raises(KeyError, lambda: n.output(1))
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def test_node_caption():
    n = Node()
    assert n.caption() == "caption"

    n.set_caption("toto")
    assert n.caption() == "toto"
    n.set_caption(1)
    assert n.caption() == "1"
Ejemplo n.º 10
0
def test_portgraph_set_actor_port_order_not_important():
    pg = PortGraph()

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

    vid = pg.add_vertex()
    for k in reversed(keys):
        pg.add_in_port(vid, k)
        pg.add_out_port(vid, k)

    pg.set_actor(vid, actor)
    assert pg.actor(vid) == actor
Ejemplo n.º 11
0
def test_node_priority():
    n = Node()
    assert n.priority() == 0

    n.set_priority(1)
    assert n.priority() == 1

    assert_raises(TypeError, lambda: n.set_priority(1.1))
    assert_raises(TypeError, lambda: n.set_priority("bcp"))
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def test_node_priority():
    n = Node()
    assert n.priority() == 0

    n.set_priority(1)
    assert n.priority() == 1

    assert_raises(TypeError, lambda: n.set_priority(1.1))
    assert_raises(TypeError, lambda: n.set_priority("bcp"))
Ejemplo n.º 14
0
def test_portgraph_set_actor_port_order_not_important():
    pg = PortGraph()

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

    vid = pg.add_vertex()
    for k in reversed(keys):
        pg.add_in_port(vid, k)
        pg.add_out_port(vid, k)

    pg.set_actor(vid, actor)
    assert pg.actor(vid) == actor
Ejemplo n.º 15
0
def test_node_port_is_mutable():
    n = Node()
    n.add_input(1)
    n.add_output(1)
    n.input(1).type = "IInt"
    n.input(1).default = 0
    n.input(1).descr = "toto"

    n.output(1).type = "IFloat"
    n.output(1).default = 'a'
    n.output(1).descr = "titi"

    assert n.input(1).type == "IInt"
    assert n.input(1).default == 0
    assert n.input(1).descr == "toto"

    assert n.output(1).type == "IFloat"
    assert n.output(1).default == 'a'
    assert n.output(1).descr == "titi"
Ejemplo n.º 16
0
def test_node_is_lazy_by_default():
    n = Node()
    assert n.is_lazy()

    n.set_lazy(True)
    assert n.is_lazy()
    n.set_lazy(False)
    assert not n.is_lazy()
    n.set_lazy(True)
    assert n.is_lazy()
Ejemplo n.º 17
0
def test_node_port_default_value():
    n = Node()
    n.add_input("in1", "IInt")
    n.add_input("in2", "IInt", 0)
    n.add_input("in3", default='a')
    n.add_output("out", "IFloat")

    assert_raises(KeyError, lambda: n.input("toto"))
    assert_raises(KeyError, lambda: n.output("toto"))

    assert n.input("in1").default is None
    assert n.input("in2").default == 0
    assert n.input("in3").default == 'a'
    assert n.output("out").type == "IFloat"
Ejemplo n.º 18
0
def test_node_creation():
    n = Node()
    assert n.get_id() == "openalea.workflow.node:Node"

    assert_raises(NotImplementedError, lambda: n.reset())
    assert_raises(NotImplementedError, lambda: n())
Ejemplo n.º 19
0
def test_node_ports_order_is_preserved():
    n = Node()
    n.add_output('a1', "descr")
    n.add_output('a2', "descr")
    n.add_output('res', "descr")
    assert tuple(n.outputs()) == ('a1', 'a2', 'res')
Ejemplo n.º 20
0
def test_node_port_keys_are_locally_unique():
    n = Node()
    n.add_input(1, "titi")
    assert len(list(n.inputs())) == 1
    n.add_input("toto", "titi")
    assert len(list(n.inputs())) == 2

    assert_raises(KeyError, lambda: n.add_input(1, "toto"))

    n.add_output(1, "tata")
    assert len(list(n.outputs())) == 1
    n.add_output("toto", "tata")
    assert len(list(n.outputs())) == 2

    assert_raises(KeyError, lambda: n.add_output("toto", "toto"))
Ejemplo n.º 21
0
def test_node_ports_are_empty_on_creation():
    n = Node()
    assert len(list(n.inputs())) == 0
    assert len(list(n.outputs())) == 0
Ejemplo n.º 22
0
def test_node_ports_are_empty_on_creation():
    n = Node()
    assert len(list(n.inputs())) == 0
    assert len(list(n.outputs())) == 0
Ejemplo n.º 23
0
def test_node_port_keys_are_locally_unique():
    n = Node()
    n.add_input(1, "titi")
    assert len(list(n.inputs())) == 1
    n.add_input("toto", "titi")
    assert len(list(n.inputs())) == 2

    assert_raises(KeyError, lambda: n.add_input(1, "toto"))

    n.add_output(1, "tata")
    assert len(list(n.outputs())) == 1
    n.add_output("toto", "tata")
    assert len(list(n.outputs())) == 2

    assert_raises(KeyError, lambda: n.add_output("toto", "toto"))
Ejemplo n.º 24
0
def test_node_is_lazy_by_default():
    n = Node()
    assert n.is_lazy()

    n.set_lazy(True)
    assert n.is_lazy()
    n.set_lazy(False)
    assert not n.is_lazy()
    n.set_lazy(True)
    assert n.is_lazy()
Ejemplo n.º 25
0
def test_node_ports_order_is_preserved():
    n = Node()
    n.add_output("a1", "descr")
    n.add_output("a2", "descr")
    n.add_output("res", "descr")
    assert tuple(n.outputs()) == ("a1", "a2", "res")
Ejemplo n.º 26
0
def test_node_creation():
    n = Node()
    assert n.get_id() == "openalea.workflow.node:Node"

    assert_raises(NotImplementedError, lambda: n.reset())
    assert_raises(NotImplementedError, lambda: n())
Ejemplo n.º 27
0
def test_node_port_is_mutable():
    n = Node()
    n.add_input(1)
    n.add_output(1)
    n.input(1).type = "IInt"
    n.input(1).default = 0
    n.input(1).descr = "toto"

    n.output(1).type = "IFloat"
    n.output(1).default = "a"
    n.output(1).descr = "titi"

    assert n.input(1).type == "IInt"
    assert n.input(1).default == 0
    assert n.input(1).descr == "toto"

    assert n.output(1).type == "IFloat"
    assert n.output(1).default == "a"
    assert n.output(1).descr == "titi"
Ejemplo n.º 28
0
def test_node_port_default_value():
    n = Node()
    n.add_input("in1", "IInt")
    n.add_input("in2", "IInt", 0)
    n.add_input("in3", default="a")
    n.add_output("out", "IFloat")

    assert_raises(KeyError, lambda: n.input("toto"))
    assert_raises(KeyError, lambda: n.output("toto"))

    assert n.input("in1").default is None
    assert n.input("in2").default == 0
    assert n.input("in3").default == "a"
    assert n.output("out").type == "IFloat"