def test_dataflow_state_get_data():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")
    vid5 = df.add_vertex()
    pid51 = df.add_out_port(vid5, "out")

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

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

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)
    df.connect(pid51, pid32)

    dfs = DataflowState(df)

    for pid in df.ports():
        raises(KeyError, lambda: dfs.get_data(pid))

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        dfs.set_data(pid, i)

    raises(KeyError, lambda: dfs.get_data(pid10))

    dfs.set_data(pid10, 'a')
    assert dfs.get_data(pid10) == 'a'

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        assert dfs.get_data(pid) == i

    assert dfs.get_data(pid31) == 0
    assert tuple(dfs.get_data(pid32)) == (1, 3)
    assert dfs.get_data(pid41) == 2

    n2 = Node()
    df.set_actor(vid2, n2)

    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n5 = Node()
    df.set_actor(vid5, n5)
    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n2.get_ad_hoc_dict().set_metadata('position', [10, 0])
    n5.get_ad_hoc_dict().set_metadata('position', [0, 0])
    assert tuple(dfs.get_data(pid32)) == (3, 1)
Example #2
0
def test_dataflow_state_get_data():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")
    vid5 = df.add_vertex()
    pid51 = df.add_out_port(vid5, "out")

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

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

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)
    df.connect(pid51, pid32)

    dfs = DataflowState(df)

    for pid in df.ports():
        assert_raises(KeyError, lambda: dfs.get_data(pid))

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        dfs.set_data(pid, i)

    assert_raises(KeyError, lambda: dfs.get_data(pid10))

    dfs.set_data(pid10, 'a')
    assert dfs.get_data(pid10) == 'a'

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        assert dfs.get_data(pid) == i

    assert dfs.get_data(pid31) == 0
    assert tuple(dfs.get_data(pid32)) == (1, 3)
    assert dfs.get_data(pid41) == 2

    n2 = Node()
    df.set_actor(vid2, n2)

    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n5 = Node()
    df.set_actor(vid5, n5)
    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n2.get_ad_hoc_dict().set_metadata('position', [10, 0])
    n5.get_ad_hoc_dict().set_metadata('position', [0, 0])
    assert tuple(dfs.get_data(pid32)) == (3, 1)
Example #3
0
def test_dataflow():
    """ test dataflow"""
    df=DataFlow()
    vid1=df.add_vertex()
    pid11=df.add_out_port(vid1, "out")
    vid2=df.add_vertex()
    pid21=df.add_out_port(vid2, "out")

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

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

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

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

    test=False
    try:
        dummy=df.connect(pid11, pid33)
    except PortError:
        test=True
    assert test


    df.remove_port(pid33)
    assert set(df.connected_ports(pid41))==set()
    assert set(df.out_edges(vid3))==set()
    test=False
    try:
        dummy=df.port(pid33)
    except PortError:
        test=True
    assert test
Example #4
0
def test_dataflow():
    """ test dataflow"""
    df = DataFlow()
    vid1 = df.add_vertex()
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

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

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

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

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

    test = False
    try:
        dummy = df.connect(pid11, pid33)
    except PortError:
        test = True
    assert test

    df.remove_port(pid33)
    assert set(df.connected_ports(pid41)) == set()
    assert set(df.out_edges(vid3)) == set()
    test = False
    try:
        dummy = df.port(pid33)
    except PortError:
        test = True
    assert test