Esempio n. 1
0
    def test_add_node(self):
        g = Graph()
        g.add_node(node("A"))

        expected = {"nodes": ["A"], "edges": [], "clusters": {}}

        assert g.to_dict() == expected

        g.add_node(node("A"))

        assert g.to_dict() == expected
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
    def test_dig_node_not_found(self):
        g = Graph()
        g.add_node(node("jig"))

        with pytest.raises(ValueError):
            g.dig(node("foo"))