Exemple #1
0
def test_network_deserialization(serialized_graph):

    comp_map = {
        'rill.components.basic/Counter': Counter,
        'rill.components.merge/Group': Group,
        'tests.components/Discard': Discard,
        'tests.subnets/PassthruNet': PassthruNet,
        'tests.components/GenerateArray': GenerateArray
    }
    graph = Graph.from_dict(serialized_graph, component_lookup=comp_map)

    assert len(graph.get_components().keys()) == 5

    Counter1 = graph.get_component('Counter1')
    Discard1 = graph.get_component('Discard1')
    Pass = graph.get_component('Pass')
    Generate = graph.get_component('Generate')
    Merge = graph.get_component('Merge')

    assert Counter1.ports.OUT._connections[0].inport.component is Pass
    assert Counter1.metadata == {
        'x': 20.0,
        'y': 300.5
    }
    assert Pass.ports.OUT._connections[0].inport.component is Discard1
    assert Counter1.ports.IN._connection._content == [5]

    assert (
        Generate.ports.OUT.get_element(0)._connections[0].inport.component is Merge
    )

    assert (
        Generate.ports.OUT.get_element(1)._connections[0].inport.component is Merge
    )

    assert (
        Generate.ports.OUT.get_element(0)._connections[0].inport.index is 1
    )

    assert (
        Generate.ports.OUT.get_element(1)._connections[0].inport.index is 2
    )

    expected = graph.to_dict()

    # Order of connections array shouldn't matter
    expected['connections'] = sorted(expected['connections'], key=str)

    assert serialized_graph == expected
Exemple #2
0
import ast
from rill.engine.network import Graph, Network
from rill.components.hello_world import LineToWords, StartsWith, WordsToLine, Output

graph_file = open('example_serialized.txt')
graph_str = graph_file.read()
graph_file.close()
graph_from_file = ast.literal_eval(graph_str)

graph = Graph.from_dict(graph_from_file)
net = Network(graph)
net.go()
Exemple #3
0
def test_export_of_exports():
    definition = {
        'processes': {
            'Head': {
                'component': 'rill.components.timing/SlowPass',
                'metadata': {}
            },
            'Tail': {
                'component': 'rill.components.timing/SlowPass',
                'metadata': {}
            }
        },
        'connections': [
            {
                'src': {'data': 0.01},
                'tgt': {
                    'process': 'Head',
                    'port': 'DELAY'
                }
            },
            {
                'src': {'data': 0.01},
                'tgt': {
                    'process': 'Tail',
                    'port': 'DELAY'
                }
            },
            {
                'src': {
                    'process': 'Head',
                    'port': 'OUT'
                },
                'tgt': {
                    'process': 'Tail',
                    'port': 'IN'
                }
            }
        ],
        'inports': {
            'IN': {
                'process': 'Head',
                'port': 'IN',
                'metadata': {}
            }
        },
        'outports': {
            'OUT': {
                'process': 'Tail',
                'port': 'OUT',
                'metadata': {}
            }
        }
    }

    graph = Graph.from_dict(definition, {
        'rill.components.timing/SlowPass': SlowPass
    })

    Head = graph.get_component('Head')
    Tail = graph.get_component('Tail')

    assert Head.ports.OUT._connections[0].inport.component is Tail

    expected = graph.to_dict()

    # Order of connections array shouldn't matter
    definition['connections'] = sorted(definition['connections'], key=str)
    expected['connections'] = sorted(expected['connections'], key=str)

    assert definition == expected