Example #1
0
def test_get_node_when_node_is_disabled(raw_manifest):
    manifest = Manifest(raw_manifest)

    node = manifest.get_node("x")

    assert node.id == "x"
    assert isinstance(node, Node)
Example #2
0
    def run(self, manifest: Manifest) -> List[MetricResult]:
        graph = manifest.graph
        degree_centrality = nx.centrality.degree_centrality(graph)
        in_degree_centrality = nx.centrality.in_degree_centrality(graph)
        out_degree_centrality = nx.centrality.out_degree_centrality(graph)
        closeness_centrality = nx.centrality.closeness_centrality(graph)
        betweenness_centrality = nx.centrality.betweenness_centrality(graph)
        pagerank = nx.link_analysis.pagerank_alg.pagerank(graph)

        results = []
        for node in graph.nodes:
            results.append(
                MetricResult(
                    manifest.get_node(node),
                    degree_centrality[node],
                    in_degree_centrality[node],
                    out_degree_centrality[node],
                    closeness_centrality[node],
                    betweenness_centrality[node],
                    pagerank[node],
                ))

        return results
Example #3
0
def test_get_node_when_node_does_not_exist(raw_manifest):
    manifest = Manifest(raw_manifest)

    with pytest.raises(KeyError):
        manifest.get_node("foo")