def test_edges_with_data_equal(self): G = nx.MultiGraph() nx.add_path(G, [0, 1, 2], weight=1) H = nx.MultiGraph() nx.add_path(H, [0, 1, 2], weight=1) self._test_equal(G.edges(data=True, keys=True), H.edges(data=True, keys=True))
def test_all_simple_paths_multigraph(self): G = nx.MultiGraph([(1, 2), (1, 2)]) paths = nx.builtin.all_simple_paths(G, 1, 1) assert list(paths) == [] nx.add_path(G, [3, 1, 10, 2]) paths = list(nx.builtin.all_simple_paths(G, 1, 2)) assert len(paths) == 3 assert {tuple(p) for p in paths} == {(1, 2), (1, 2), (1, 10, 2)}
def _init_product_graph(G, H): if not G.is_directed() == H.is_directed(): msg = "G and H must be both directed or both undirected" raise nx.NetworkXError(msg) if G.is_multigraph() or H.is_multigraph(): GH = nx.MultiGraph() else: GH = nx.Graph() if G.is_directed(): GH = GH.to_directed() return GH
def test_multigraph_numpy(self): with pytest.raises(nx.NetworkXException): e = nx.eigenvector_centrality_numpy(nx.MultiGraph())
def test_multigraph(self): with pytest.raises(nx.NetworkXException): e = nx.katz_centrality(nx.MultiGraph(), 0.1)
def test_multigraphs_equal(self): G = nx.path_graph(4, create_using=nx.MultiGraph()) H = nx.MultiGraph() nx.add_path(H, range(4)) self._test_equal(G, H)
def test_no_edges(self): G = nx.MultiGraph() H = nx.MultiGraph() self._test_equal(G.edges(data=True, keys=True), H.edges(data=True, keys=True))
def test_multigraph(self): G = nx.MultiGraph([(0, 1), (0, 1)]) assert nx.builtin.is_simple_path(G, [0, 1])
def test_all_simple_edge_paths_multigraph_with_cutoff(self): G = nx.MultiGraph([(1, 2), (1, 2), (1, 10), (10, 2)]) paths = list(nx.builtin.all_simple_edge_paths(G, 1, 2, cutoff=1)) assert len(paths) == 2 assert {tuple(p) for p in paths} == {((1, 2, 0), ), ((1, 2, 1), )}