def test_remove_and_dig(self): """ エッジの生えていないクラスタ内ノードが発生したとき、エラーにならずそのノードがGraphのnodesに追加されること """ master_graph = MasterGraph.from_tuple_list([ ("tests.fixtures", "jig.visualizer"), ("tests.visualizer", "jig.visualizer"), ]) g = Graph(master_graph=master_graph) assert g.to_dict() == { "nodes": ["jig", "tests"], "edges": [("tests", "jig")], "clusters": {}, } g.remove_node(node("jig")) assert g.to_dict() == { "nodes": ["tests"], "edges": [], "clusters": {}, } g.dig(node("tests")) assert g.to_dict() == { "nodes": ["tests.fixtures", "tests.visualizer"], "edges": [], "clusters": { "tests": { "nodes": ["tests.fixtures", "tests.visualizer"], "clusters": {}, } }, }
def test_is_removed_node(self): # クラスタ内クラスタの削除 master_graph = MasterGraph.from_tuple_list([ ("jig.collector.application", "jig.collector.domain.source_code"), ("jig.collector.application", "jig.collector.domain.source_file"), ( "jig.collector.domain.source_code", "jig.collector.domain.source_file", ), ("jig.cli.main", "jig.collector.application"), ]) g = Graph(master_graph=master_graph) g.dig(node("jig")) g.dig(node("jig.collector")) assert g.to_dict() == { "nodes": ["jig.cli", "jig.collector.application", "jig.collector.domain"], "edges": [ ("jig.cli", "jig.collector.application"), ("jig.collector.application", "jig.collector.domain"), ], "clusters": { "jig": { "clusters": { "jig.collector": { "nodes": [ "jig.collector.application", "jig.collector.domain", ], "clusters": {}, } }, "nodes": ["jig.cli"], }, }, } assert g.is_removed_node(node("the.name.is.not.in.the.graph")) is False assert g.is_removed_node(node("jig")) is False assert g.is_removed_node(node("jig.cli")) is False assert g.is_removed_node(node("jig.collector")) is False assert g.is_removed_node(node("jig.collector.application")) is False assert g.is_removed_node(node("jig.collector.domain")) is False g.remove_node(node("jig.cli")) assert g.is_removed_node(node("jig.cli")) is True assert g.is_removed_node(node("jig")) is False g.remove_node(node("jig.collector.application")) assert g.is_removed_node(node("jig.collector.application")) is True assert g.is_removed_node(node("jig.collector")) is False g.remove_node(node("jig.collector.domain")) assert g.is_removed_node(node("jig.collector.domain")) is True assert g.is_removed_node(node("jig.collector")) is True assert g.is_removed_node(node("jig")) is True
def test_restore(self): # クラスタ内クラスタの削除 master_graph = MasterGraph.from_tuple_list([ ("jig.collector.application", "jig.collector.domain.source_code"), ("jig.collector.application", "jig.collector.domain.source_file"), ( "jig.collector.domain.source_code", "jig.collector.domain.source_file", ), ("jig.cli.main", "jig.collector.application"), ]) g = Graph(master_graph=master_graph) g.dig(node("jig")) g.dig(node("jig.collector")) assert g.to_dict() == { "nodes": ["jig.cli", "jig.collector.application", "jig.collector.domain"], "edges": [ ("jig.cli", "jig.collector.application"), ("jig.collector.application", "jig.collector.domain"), ], "clusters": { "jig": { "clusters": { "jig.collector": { "nodes": [ "jig.collector.application", "jig.collector.domain", ], "clusters": {}, } }, "nodes": ["jig.cli"], }, }, } # 存在しないノード with pytest.raises(InvalidRestoreTargetError): g.restore_node(node("invalid.node.name")) # 削除されていないノード with pytest.raises(InvalidRestoreTargetError): g.restore_node(node("jig.cli")) before_dict = g.to_dict() # 接続先があるノードの復元 g.remove_node(node("jig.cli")) g.restore_node(node("jig.cli")) assert g.to_dict() == before_dict # 接続元があるノードの復元 g.remove_node(node("jig.collector.domain")) g.restore_node(node("jig.collector.domain")) assert g.to_dict() == before_dict
def test_remove_and_dig_inside_cluster(self): """ エッジの生えていないノードがネストされたクラスタ内で発生したとき、そのノードがGraphのnodesに追加されること """ master_graph = MasterGraph.from_tuple_list([("tests.fixtures.download", "jig.visualizer")]) g = Graph(master_graph=master_graph) assert g.to_dict() == { "nodes": ["jig", "tests"], "edges": [("tests", "jig")], "clusters": {}, } g.dig(node("tests")) assert g.to_dict() == { "nodes": ["jig", "tests.fixtures"], "edges": [("tests.fixtures", "jig")], "clusters": { "tests": { "nodes": ["tests.fixtures"], "clusters": {} } }, } g.remove_node(node("jig")) assert g.to_dict() == { "nodes": ["tests.fixtures"], "edges": [], "clusters": { "tests": { "nodes": ["tests.fixtures"], "clusters": {} } }, } g.dig(node("tests.fixtures")) assert g.to_dict() == { "nodes": ["tests.fixtures.download"], "edges": [], "clusters": { "tests": { "nodes": [], "clusters": { "tests.fixtures": { "nodes": ["tests.fixtures.download"], "clusters": {}, } }, } }, }
def test_remove_cluster__child_cluster(self): # クラスタ内クラスタの削除 master_graph = MasterGraph.from_tuple_list([ ("jig.collector.application", "jig.collector.domain.source_code"), ("jig.collector.application", "jig.collector.domain.source_file"), ( "jig.collector.domain.source_code", "jig.collector.domain.source_file", ), ("jig.cli.main", "jig.collector.application"), ]) g = Graph(master_graph=master_graph) g.dig(node("jig")) g.dig(node("jig.collector")) assert g.to_dict() == { "nodes": ["jig.cli", "jig.collector.application", "jig.collector.domain"], "edges": [ ("jig.cli", "jig.collector.application"), ("jig.collector.application", "jig.collector.domain"), ], "clusters": { "jig": { "clusters": { "jig.collector": { "nodes": [ "jig.collector.application", "jig.collector.domain", ], "clusters": {}, } }, "nodes": ["jig.cli"], }, }, } g.remove_cluster(path("jig.collector")) assert g.to_dict() == { "nodes": ["jig.cli"], "edges": [], "clusters": { "jig": { "clusters": {}, "nodes": ["jig.cli"] } }, }
def test_dig_node_not_found(self): g = Graph() g.add_node(node("jig")) with pytest.raises(ValueError): g.dig(node("foo"))
def test_dig_complex(self): master_graph = MasterGraph.from_tuple_list([ ("jig.cli", "jig.analyzer"), ("jig.cli", "jig.visualizer.application"), ("jig.visualizer.application", "jig.analyzer"), ("jig.visualizer.application", "jig.visualizer.domain.edge"), ("jig.visualizer.application", "jig.visualizer.domain.node"), ("jig.visualizer.domain.edge", "jig.visualizer.domain.node"), ]) g = Graph(master_graph=master_graph) assert g.to_dict() == { "nodes": ["jig"], "edges": [], "clusters": {}, } g.dig(node("jig")) assert g.to_dict() == { "nodes": ["jig.analyzer", "jig.cli", "jig.visualizer"], "edges": [ ("jig.cli", "jig.analyzer"), ("jig.cli", "jig.visualizer"), ("jig.visualizer", "jig.analyzer"), ], "clusters": { "jig": { "nodes": ["jig.analyzer", "jig.cli", "jig.visualizer"], "clusters": {}, } }, } g.dig(node("jig.visualizer")) assert g.to_dict() == { "nodes": [ "jig.analyzer", "jig.cli", "jig.visualizer.application", "jig.visualizer.domain", ], "edges": [ ("jig.cli", "jig.analyzer"), ("jig.cli", "jig.visualizer.application"), ("jig.visualizer.application", "jig.analyzer"), ("jig.visualizer.application", "jig.visualizer.domain"), ], "clusters": { "jig": { "nodes": ["jig.analyzer", "jig.cli"], "clusters": { "jig.visualizer": { "nodes": [ "jig.visualizer.application", "jig.visualizer.domain", ], "clusters": {}, }, }, }, }, } g.dig(node("jig.visualizer.domain")) assert g.to_dict() == { "nodes": [ "jig.analyzer", "jig.cli", "jig.visualizer.application", "jig.visualizer.domain.edge", "jig.visualizer.domain.node", ], "edges": [ ("jig.cli", "jig.analyzer"), ("jig.cli", "jig.visualizer.application"), ("jig.visualizer.application", "jig.analyzer"), ("jig.visualizer.application", "jig.visualizer.domain.edge"), ("jig.visualizer.application", "jig.visualizer.domain.node"), ("jig.visualizer.domain.edge", "jig.visualizer.domain.node"), ], "clusters": { "jig": { "nodes": ["jig.analyzer", "jig.cli"], "clusters": { "jig.visualizer": { "nodes": ["jig.visualizer.application"], "clusters": { "jig.visualizer.domain": { "nodes": [ "jig.visualizer.domain.edge", "jig.visualizer.domain.node", ], "clusters": {}, }, }, }, }, }, }, }