Exemplo n.º 1
0
    def test_render__with_style(self):
        master_graph = MasterGraph.from_tuple_list([("a", "b"), ("b", "c")])
        graph = Graph(master_graph)

        graph.style(
            node("b"), color=Color.Blue, fontcolor=Color.Red, penwidth=PenWidth.Bold
        )
        renderer = GraphRenderer(graph=graph)

        g = Digraph()
        default_node_style = NodeStyle().to_dict()
        node_style = NodeStyle().to_dict()
        node_style.update(
            {
                "color": "blue",
                "fontcolor": "red",
                "penwidth": PenWidth.to_size(PenWidth.Bold),
            }
        )
        g.node("a", **default_node_style)
        g.node("b", **node_style)
        g.node("c", **default_node_style)

        edge_style = EdgeStyle().to_dict()
        edge_style.update(
            {
                "color": "blue",
                "fontcolor": "red",
                "penwidth": PenWidth.to_size(PenWidth.Bold),
            }
        )
        g.edge("a", "b", **edge_style)
        g.edge("b", "c", **edge_style)

        assert str(renderer.render()) == str(g)
Exemplo n.º 2
0
    def test_render__with_hidden_node(self):
        # +---+    +---+    +---+
        # |   |--->| b |--->|   |
        # |   |    +---+    |   |
        # | a |             | d |
        # |   |    +---+    |   |
        # |   |--->| c |--->|   |
        # +---+    +---+    +---+
        master_graph = MasterGraph.from_tuple_list(
            [("a", "b"), ("a", "c"), ("b", "d"), ("c", "d")]
        )
        graph = Graph(master_graph)
        renderer = GraphRenderer(graph=graph)

        graph.hide_node(node("b"))

        g = Digraph()

        default_node_style = NodeStyle().to_dict()
        hidden_node_style = NodeStyle(invisible=True).to_dict()
        g.node("a", **default_node_style)
        g.node("b", **hidden_node_style)
        g.node("c", **default_node_style)
        g.node("d", **default_node_style)

        default_edge_style = EdgeStyle().to_dict()
        hidden_edge_style = EdgeStyle(invisible=True).to_dict()
        g.edge("a", "b", **hidden_edge_style)
        g.edge("a", "c", **default_edge_style)
        g.edge("b", "d", **hidden_edge_style)
        g.edge("c", "d", **default_edge_style)

        assert str(renderer.render()) == str(g)
Exemplo n.º 3
0
    def test_render__reset_style(self):
        master_graph = MasterGraph.from_tuple_list([("a", "b"), ("b", "c")])
        graph = Graph(master_graph)

        graph.style(
            node("b"), color=Color.Blue, fontcolor=Color.Red, penwidth=PenWidth.Bold
        )
        graph.reset_style()
        renderer = GraphRenderer(graph=graph)

        g = Digraph()
        default_node_style = NodeStyle().to_dict()
        g.node("a", **default_node_style)
        g.node("b", **default_node_style)
        g.node("c", **default_node_style)

        default_edge_style = EdgeStyle().to_dict()
        g.edge("a", "b", **default_edge_style)
        g.edge("b", "c", **default_edge_style)

        assert str(renderer.render()) == str(g)
Exemplo n.º 4
0
    def test_render__with_autohighlight(self):
        # +---+    +---+    +---+    +---+
        # |   |    |   |--->|   |    |   |
        # | a |--->| b |    | c |--->| d |
        # |   |    |   |<---|   |    |   |
        # +---+    +---+    +---+    +---+
        master_graph = MasterGraph.from_tuple_list(
            [("a", "b"), ("b", "c"), ("c", "b"), ("c", "d")]
        )
        graph = Graph(master_graph)
        renderer = GraphRenderer(graph=graph)

        graph.auto_highlight()

        g = Digraph()

        default_node_style = NodeStyle().to_dict()
        entry_point_node_style = NodeStyle(
            color=Color.Teal, fontcolor=Color.White, filled=True
        ).to_dict()
        fundamental_node_style = NodeStyle(
            color=Color.Purple, fontcolor=Color.White, filled=True
        ).to_dict()
        g.node("a", **entry_point_node_style)
        g.node("b", **default_node_style)
        g.node("c", **default_node_style)
        g.node("d", **fundamental_node_style)

        default_edge_style = EdgeStyle().to_dict()
        warning_edge_style = EdgeStyle(
            color=Color.Red, penwidth=PenWidth.Bold
        ).to_dict()
        g.edge("a", "b", **default_edge_style)
        g.edge("b", "c", **warning_edge_style)
        g.edge("c", "b", **warning_edge_style)
        g.edge("c", "d", **default_edge_style)

        assert str(renderer.render()) == str(g)
Exemplo n.º 5
0
    def test_render(self):
        cluster = Cluster(module_path=path("jig"), children={node("jig.analyzer")})
        sub_cluster = Cluster(
            module_path=path("jig.collector"),
            children={node("jig.collector.application"), node("jig.collector.domain")},
        )
        cluster.add_cluster(sub_cluster)

        graph = Graph()
        graph.add_edge(edge("jig.analyzer", "jig.collector"))
        graph.add_cluster(cluster)

        renderer = GraphRenderer(graph=graph)

        g = Digraph()

        node_style = NodeStyle().to_dict()
        g.node("jig.analyzer", **node_style)
        g.node("jig.collector", **node_style)

        edge_style = EdgeStyle().to_dict()
        g.edge("jig.analyzer", "jig.collector", **edge_style)

        child = Digraph(name="cluster_jig")
        child.attr(label="jig")
        child.node("jig.analyzer")

        grandchild = Digraph(name="cluster_jig.collector")
        grandchild.attr(label="jig.collector")
        grandchild.node("jig.collector.application")
        grandchild.node("jig.collector.domain")

        child.subgraph(grandchild)
        g.subgraph(child)

        assert str(renderer.render()) == str(g)
Exemplo n.º 6
0
 def render(self) -> Digraph:
     renderer = GraphRenderer(self.graph)
     return renderer.render()