def test_remove_link(self, graph, sum_op, square_op): graph.add_operations(sum_op, square_op) graph.add_link(sum_op, square_op, source_param="sum", dest_param="n") graph.remove_link(sum_op, square_op, "sum", "n") assert len(graph.get_inbound_links(sum_op)) == 0 and len( graph.get_inbound_links(square_op)) == 0 assert len(graph.get_outbound_links(sum_op)) == 0 and len( graph.get_outbound_links(square_op)) == 0
def test_add_link(self, graph, sum_op, square_op): graph.add_operation(sum_op) graph.add_operation(square_op) graph.add_link(source=sum_op, dest=square_op, source_param="sum", dest_param="n") sum_inbound_links = graph.get_inbound_links(sum_op) sum_outbound_links = graph.get_outbound_links(sum_op) square_inbound_links = graph.get_inbound_links(square_op) square_outbound_links = graph.get_outbound_links(square_op) links = [("sum", "n")] assert sum_inbound_links[square_op] == [] assert sum_outbound_links[square_op] == links assert square_inbound_links[sum_op] == links assert square_outbound_links[sum_op] == []
def test_remove_operation_not_remove_orphan_links(self, graph, sum_op, square_op): graph.add_operations(sum_op, square_op) to_remove = graph.remove_operation(square_op, remove_orphan_links=False) assert graph.operations == [sum_op] assert to_remove == (graph.get_inbound_links(square_op), graph.get_outbound_links(square_op))
def test_add_multiple_links(self, graph, sum_op, square_op): graph.add_operation(sum_op) graph.add_operation(square_op) import math def my_sqrt(num): return math.sqrt(num) sqrt_op = operation(my_sqrt, output_names=("sqrt"))() graph.add_operation(sqrt_op) # sum -> square -> sqrt # \ | # -------->------ graph.add_link(source=sum_op, dest=square_op, source_param="sum", dest_param="n") graph.add_link(source=square_op, dest=sqrt_op, source_param="square", dest_param="num") graph.add_link(source=sum_op, dest=sqrt_op, source_param="sum", dest_param="num") # sum -> square assert graph.get_inbound_links(sum_op)[square_op] == [] assert graph.get_outbound_links(sum_op)[square_op] == [("sum", "n")] assert graph.get_inbound_links(square_op)[sum_op] == [("sum", "n")] assert graph.get_outbound_links(square_op)[sum_op] == [] # square -> sqrt assert graph.get_inbound_links(square_op)[sqrt_op] == [] assert graph.get_outbound_links(square_op)[sqrt_op] == [("square", "num")] assert graph.get_inbound_links(sqrt_op)[square_op] == [("square", "num")] assert graph.get_outbound_links(sqrt_op)[square_op] == [] # sum -> sqrt assert graph.get_inbound_links(sum_op)[sqrt_op] == [] assert graph.get_outbound_links(sum_op)[sqrt_op] == [("sum", "num")] assert graph.get_inbound_links(sqrt_op)[sum_op] == [("sum", "num")] assert graph.get_outbound_links(sqrt_op)[sum_op] == []
def test_clear_operation_links_empty(self, graph, sum_op): graph.clear_operation_links(sum_op) assert graph.links() == [] assert graph.get_outbound_links(sum_op) == {} assert graph.get_inbound_links(sum_op) == {}
def test_get_inbound_links_empty(self, graph, sum_op): assert graph.get_inbound_links(sum_op) == {}
def test_get_inbound_links(self, graph, sum_op, square_op): graph.add_operations(sum_op, square_op) graph.add_link(sum_op, square_op, "sum", "n") assert graph.get_inbound_links(sum_op) == {} assert graph.get_inbound_links(square_op) == {sum_op: [("sum", "n")]}