def test_deepcopy(): node_a = Node(title="a", inner_widget=InnerWidget()) node_a.add_input_port("inputport", port_type=str) node_a.add_output_port("value", port_type=int) node_b = Node(title="b") node_b.add_input_port("value", port_type=int) node_a.outputs["value"].connect_to(node_b.inputs["value"]) node_a_clone = deepcopy(node_a) assert node_a_clone.inner_widget is not node_a.inner_widget assert len(node_a_clone.inputs) == 1 assert len(node_a_clone.outputs) == 1 # Only connections are not copied assert len(node_a_clone.outputs["value"].connections) == 0
def test_compose_graphics_scene(qtbot): node_a = Node(title="node_a") out = node_a.add_output_port(name="out", port_type=int) node_b = Node(title="node_b") in1 = node_b.add_input_port(name="in1", port_type=int) in2 = node_b.add_input_port(name="in2", port_type=int) # Graphics Nodes graphics_node_a = GraphicsNodeFactory(node_a) graphics_node_b = GraphicsNodeFactory(node_b) # Graphics Connections in1_out_connection = GraphicsConnectionFactory() in1_out_connection.start_graphics_port = in1.graphics_port in1_out_connection.end_graphics_port = out.graphics_port assert len(graphics_node_a._output_graphics_ports["out"]. graphics_connections) == 1 assert len( graphics_node_b._input_graphics_ports["in1"].graphics_connections) == 1 in2_out_connection = GraphicsConnectionFactory() in2_out_connection.start_graphics_port = in2.graphics_port in2_out_connection.end_graphics_port = out.graphics_port assert len(graphics_node_a._output_graphics_ports["out"]. graphics_connections) == 2 assert len( graphics_node_b._input_graphics_ports["in1"].graphics_connections) == 1 assert len( graphics_node_b._input_graphics_ports["in2"].graphics_connections) == 1
def node_b(): node = Node(title="b") node.add_input_port(name="in_int", port_type=int) node.add_input_port(name="in_str", port_type=str) node.add_output_port(name="out_int", port_type=int) node.add_output_port(name="out_str", port_type=str) return node
def test_compose_graphics_scene_from_connected_nodes(qtbot): node_a = Node(title="node_a") node_a.add_output_port(name="out", port_type=int) node_b = Node(title="node_b") node_b.add_input_port(name="in1", port_type=int) node_b.add_input_port(name="in2", port_type=int) node_a.outputs["out"].connect_to(node_b.inputs["in1"]) node_a.outputs["out"].connect_to(node_b.inputs["in2"]) assert node_a.outputs["out"] in node_b.inputs["in1"].connections assert node_a.outputs["out"] in node_b.inputs["in2"].connections graphics_node_a = GraphicsNodeFactory(node_a) graphics_node_b = GraphicsNodeFactory(node_b) assert len(graphics_node_a._output_graphics_ports["out"]. graphics_connections) == 2 assert len( graphics_node_b._input_graphics_ports["in1"].graphics_connections) == 1 assert len( graphics_node_b._input_graphics_ports["in2"].graphics_connections) == 1
def test_save_and_load_scene(): node_a = Node(title="a") node_a.add_output_port("out", port_type=int) node_b = Node(title="b") node_b.add_input_port("in", port_type=int) node_a.outputs["out"].connect_to(node_b.inputs["in"]) scene = Scene() scene.add_node(node_a) scene.add_node(node_b) obj = pickle.dumps(scene) loaded_scene = pickle.loads(obj) loaded_node_a = loaded_scene.nodes[0] loaded_node_b = loaded_scene.nodes[1] assert node_a == loaded_node_a assert node_b == loaded_node_b assert node_b.inputs["in"] in node_a.outputs["out"].connections assert node_a.outputs["out"] in node_b.inputs["in"].connections
def node_b(): """Empty node b. Allows multiple connections to different ports. """ return Node(title="b")