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
def get_graph(graph_name): graph = Graph(name=graph_name) gen = graph.add_component('Generate', GenerateTestData) gen.metadata['x'] = 5 gen.metadata['y'] = 5 passthru = graph.add_component('Pass', Passthru) outside = graph.add_component('Outside', Passthru) graph.connect('Generate.OUT', 'Pass.IN') graph.connect('Outside.OUT', 'Pass.IN') graph.initialize(5, 'Generate.COUNT') graph.export('Pass.OUT', 'OUTPORT') graph.export('Outside.IN', 'INPORT') return graph, gen, passthru, outside
def test_basic_connections(): graph = Graph() count = graph.add_component("Count", Counter) dis = graph.add_component("Discard1", Discard) graph.add_component("Discard2", Discard) # ports are stored in the order they are declared assert names(count.outports) == ['OUT', 'COUNT'] # assert list(count.ports._ports.keys()) == ['OUT', 'COUNT', 'NULL'] # nothing is connected yet assert count.ports['OUT'].is_connected() is False assert dis.ports['IN'].is_connected() is False with pytest.raises(FlowError): # non-existent port graph.connect("Count.FOO", "Discard1.IN") with pytest.raises(FlowError): # non-existent Component graph.connect("Foo.FOO", "Discard1.IN") # make a connection graph.connect("Count.OUT", "Discard1.IN") # outports can have more than one connection graph.connect("Count.OUT", "Discard2.IN") with pytest.raises(FlowError): # connected ports cannot be initialized graph.initialize(1, "Discard1.IN") assert type(count.ports['OUT']) is OutputPort assert type(dis.ports['IN']) is InputPort assert count.ports['OUT'].is_connected() is True assert dis.ports['IN'].is_connected() is True # FIXME: move this to a different test net = Network(graph) net.reset() net._build_runners() net._open_ports() assert count.ports['OUT'].component is count assert isinstance(count.ports['OUT'].sender, ComponentRunner) assert dis.ports['IN'].component is dis assert isinstance(dis.ports['IN'].receiver, ComponentRunner)