Exemple #1
0
def test_network_serialization(serialized_graph):
    graph = Graph()

    counter = graph.add_component('Counter1', Counter)
    counter.metadata.update({
        'x': 20.0,
        'y': 300.5
    })
    graph.add_component('Pass', PassthruNet)
    graph.add_component('Discard1', Discard)
    graph.add_component('Generate', GenerateArray)
    graph.add_component("Merge", Group)
    graph.connect('Counter1.OUT', 'Pass.IN')
    graph.connect('Pass.OUT', 'Discard1.IN')
    graph.connect("Generate.OUT[0]", "Merge.IN[1]")
    graph.connect("Generate.OUT[1]", "Merge.IN[2]")

    graph.initialize(5, "Counter1.IN")

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

    definition = graph.to_dict()

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

    assert definition == serialized_graph
Exemple #2
0
def test_export_serialization():
    graph = Graph()

    graph.add_component('Head', SlowPass, DELAY=0.01)
    graph.add_component('Tail', SlowPass, DELAY=0.01)

    graph.connect('Head.OUT', 'Tail.IN')

    graph.export('Head.IN', 'IN')
    graph.export('Tail.OUT', 'OUT')

    definition = graph.to_dict()
    expected = {
        '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': {}
            }
        }
    }

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

    assert definition == expected