示例#1
0
    def test_adding_edge_when_no_nodes_does_not_add_an_adge(self) -> None:
        """Test if adding an edge to empty graph fails as expected."""
        source_id = _get_random_string()
        target_id = _get_random_string()

        graph = Graph()
        graph.add_edge(source_id=source_id, target_id=target_id)

        self.assertEqual([], graph.edges)
示例#2
0
    def test_adding_edge_between_nodes_works(self) -> None:
        """Test adding an edge."""
        source = _get_random_node()
        target = _get_random_node()

        graph = Graph()
        graph.add_node(source)
        graph.add_node(target)
        graph.add_edge(source_id=source.id, target_id=target.id)

        edges = graph.edges
        self.assertEqual(1, len(edges))

        edge = edges[0]
        self.assertEqual(source, edge._source)
        self.assertEqual(target, edge._target)
示例#3
0
    def test_collapsing_external_group(self) -> None:
        """Test that no collapsing will happen when all groups are expanded."""
        source = self._get_source_graph()

        expected = Graph()
        expected.add_node(_create_simple_node("input", []))
        expected.add_node(_create_simple_node("a:b", ["a"]))
        expected.add_node(_create_group_node("a:b"))
        expected.add_node(_create_simple_node("e", ["e"]))
        expected.add_node(_create_simple_node("output", []))
        expected.add_edge("input", "a:b")
        expected.add_edge("a:b", "node_group_a:b")
        expected.add_edge("node_group_a:b", "output")
        expected.add_edge("input", "e")
        expected.add_edge("e", "output")

        collapser = Collapser(["node_group_a"])
        collapsed = collapser.collapse(graph=source)

        self.assertEqual(expected, collapsed)
示例#4
0
    def _get_source_graph(self) -> Graph:
        """Return a graph with a well-known contents."""
        graph = Graph()
        graph.add_node(_create_simple_node("input", []))
        graph.add_node(_create_simple_node("a:b", ["a"]))
        graph.add_node(_create_simple_node("a:b:c1", ["a", "a:b"]))
        graph.add_node(_create_simple_node("a:b:c2", ["a", "a:b"]))
        graph.add_node(_create_simple_node("a:b:c:d", ["a", "a:b", "a:b:c"]))
        graph.add_node(_create_simple_node("e", ["e"]))
        graph.add_node(_create_simple_node("output", []))

        graph.add_edge("input", "a:b")
        graph.add_edge("a:b", "a:b:c1")
        graph.add_edge("a:b", "a:b:c2")
        graph.add_edge("a:b:c1", "a:b:c:d")
        graph.add_edge("a:b:c2", "a:b:c:d")
        graph.add_edge("a:b:c:d", "output")
        graph.add_edge("input", "e")
        graph.add_edge("e", "output")

        return graph