Example #1
0
    def test_focus__node_inside_a_package(self):
        g = Graph()
        g.add_edge(edge("A", "B"))
        g.add_cluster(cluster("pkg", {"A"}))

        assert g.to_dict() == {
            "nodes": ["A", "B"],
            "edges": [("A", "B")],
            "clusters": {
                "pkg": {
                    "nodes": ["A"],
                    "clusters": {}
                }
            },
        }

        g.focus_nodes(node("A"))

        assert g.to_dict() == {
            "nodes": ["A"],
            "edges": [],
            "clusters": {
                "pkg": {
                    "nodes": ["A"],
                    "clusters": {}
                }
            },
        }
Example #2
0
    def test_remove_cluster(self):
        # Graph所有のクラスタ削除
        g = Graph()
        g.add_edge(edge("A", "B"))
        g.add_cluster(cluster("pkg", {"A"}))

        assert g.to_dict() == {
            "nodes": ["A", "B"],
            "edges": [("A", "B")],
            "clusters": {
                "pkg": {
                    "nodes": ["A"],
                    "clusters": {}
                }
            },
        }

        g.remove_cluster(path("pkg"))

        assert g.to_dict() == {
            "nodes": ["B"],
            "edges": [],
            "clusters": {},
        }

        # 冪等なこと
        g.remove_cluster(path("pkg"))

        assert g.to_dict() == {
            "nodes": ["B"],
            "edges": [],
            "clusters": {},
        }
Example #3
0
    def test_add_cluster(self):
        g = Graph()
        g.add_edge(edge("A", "B"))
        g.add_cluster(cluster("pkg", {"A", "B"}))

        assert g.to_dict() == {
            "nodes": ["A", "B"],
            "edges": [("A", "B")],
            "clusters": {
                "pkg": {
                    "nodes": ["A", "B"],
                    "clusters": {}
                }
            },
        }

        g.clusters[path("pkg")].add_cluster(cluster("pkg.child", {"C"}))
        assert g.to_dict() == {
            "nodes": ["A", "B"],
            "edges": [("A", "B")],
            "clusters": {
                "pkg": {
                    "nodes": ["A", "B"],
                    "clusters": {
                        "pkg.child": {
                            "clusters": {},
                            "nodes": ["C"]
                        }
                    },
                }
            },
        }

        # 親グラフが持っていないノードを含むクラスタが追加されたら、
        # 親グラフに含まれないノードを親グラフのノード管理に含める
        g.add_cluster(cluster("pkg_x", {"X"}))
        assert g.to_dict() == {
            "nodes": ["A", "B", "X"],
            "edges": [("A", "B")],
            "clusters": {
                "pkg": {
                    "nodes": ["A", "B"],
                    "clusters": {
                        "pkg.child": {
                            "clusters": {},
                            "nodes": ["C"]
                        }
                    },
                },
                "pkg_x": {
                    "nodes": ["X"],
                    "clusters": {}
                },
            },
        }
Example #4
0
    def test_find_node_owner(self):
        g = Graph()
        g.add_node(node("A"))
        g.add_node(node("B"))

        child_cluster = cluster("pkg", {"B"})
        g.add_cluster(child_cluster)

        assert g.find_node_owner(node("foo")) is None
        assert g.find_node_owner(node("pkg")) is None
        assert g.find_node_owner(node("A")) is g
        assert g.find_node_owner(node("B")) is child_cluster
Example #5
0
    def test_find_cluster(self):
        g = Graph()
        g.add_node(node("A"))
        g.add_node(node("B"))

        cluster_a = cluster("pkg_A", {"A"})
        cluster_b = cluster("pkg_B", {"B"})

        cluster_a.add_cluster(cluster_b)
        g.add_cluster(cluster_a)

        assert g.find_cluster(path("x")) is None
        assert g.find_cluster(path("pkg_A")) is cluster_a
        assert g.find_cluster(path("pkg_B")) is cluster_b
Example #6
0
    def test_list_all_nodes(self):
        g = Graph()
        g.add_edge(edge("A", "B"))
        g.add_edge(edge("A", "C"))

        cluster_a = cluster("pkg", {"A"})
        cluster_b = cluster("pkg.xxx", {"B"})

        cluster_a.add_cluster(cluster_b)
        g.add_cluster(cluster_a)

        assert g.list_all_nodes() == [
            node("A"),
            node("B"),
            node("C"),
        ]
Example #7
0
    def test_list_all_modules(self):
        g = Graph()
        g.add_edge(edge("A", "B"))

        cluster_a = cluster("pkg", {"A"})
        cluster_b = cluster("pkg.xxx", {"B"})

        cluster_a.add_cluster(cluster_b)
        g.add_cluster(cluster_a)

        assert g.list_all_modules() == [
            path("A"),
            path("B"),
            path("pkg"),
            path("pkg.xxx"),
        ]
Example #8
0
    def test_focus_nodes_and_clusters(self):
        g = Graph()
        g.add_edge(edge("A", "B"))
        g.add_edge(edge("C", "D"))

        cluster_a = cluster("pkg_a", {"A"})
        cluster_b = cluster("pkg_b", {"B"})

        cluster_a.add_cluster(cluster_b)
        g.add_cluster(cluster_a)

        assert g.to_dict() == {
            "nodes": ["A", "B", "C", "D"],
            "edges": [("A", "B"), ("C", "D")],
            "clusters": {
                "pkg_a": {
                    "clusters": {
                        "pkg_b": {
                            "clusters": {},
                            "nodes": ["B"]
                        }
                    },
                    "nodes": ["A"],
                }
            },
        }

        g.focus_nodes_and_clusters(node("pkg_b"), node("C"))

        assert g.to_dict() == {
            "nodes": ["B", "C"],
            "edges": [],
            "clusters": {
                "pkg_a": {
                    "clusters": {
                        "pkg_b": {
                            "clusters": {},
                            "nodes": ["B"]
                        }
                    },
                    "nodes": [],
                }
            },
        }
Example #9
0
    def test_remove_node_from_cluster(self):
        g = Graph()
        g.add_edge(edge("A", "B"))
        g.add_cluster(cluster("pkg", {"A"}))

        assert g.to_dict() == {
            "nodes": ["A", "B"],
            "edges": [("A", "B")],
            "clusters": {
                "pkg": {
                    "nodes": ["A"],
                    "clusters": {}
                }
            },
        }

        g.remove_node(node("A"))

        assert g.to_dict() == {
            "nodes": ["B"],
            "edges": [],
            "clusters": {},
        }
Example #10
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)