diff options
| author | Dan Schult <dschult@colgate.edu> | 2022-07-15 13:04:45 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-15 11:04:45 -0700 |
| commit | 15614a4e2736752b0200d3a770d83f2be2d130b9 (patch) | |
| tree | 44c298b816516b2d9d0ee85ab0e6b1b5826848f8 /networkx/classes/tests/test_multigraph.py | |
| parent | e79084b57e1553b5a1e3d80d940acc077ddb771a (diff) | |
| download | networkx-15614a4e2736752b0200d3a770d83f2be2d130b9.tar.gz | |
Update tests in base class and simple rename in convert.py (#5848)
Diffstat (limited to 'networkx/classes/tests/test_multigraph.py')
| -rw-r--r-- | networkx/classes/tests/test_multigraph.py | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/networkx/classes/tests/test_multigraph.py b/networkx/classes/tests/test_multigraph.py index f9d78dc6..0584f562 100644 --- a/networkx/classes/tests/test_multigraph.py +++ b/networkx/classes/tests/test_multigraph.py @@ -1,3 +1,5 @@ +from collections import UserDict + import pytest import networkx as nx @@ -345,6 +347,16 @@ class TestMultiGraph(BaseMultiGraphTester, _TestGraph): with pytest.raises(TypeError): G.add_edges_from([0]) + def test_multigraph_add_edges_from_four_tuple_misordered(self): + """add_edges_from expects 4-tuples of the format (u, v, key, data_dict). + + Ensure 4-tuples of form (u, v, data_dict, key) raise exception. + """ + G = nx.MultiGraph() + with pytest.raises(TypeError): + # key/data values flipped in 4-tuple + G.add_edges_from([(0, 1, {"color": "red"}, 0)]) + def test_remove_edge(self): G = self.K3 G.remove_edge(0, 1) @@ -472,12 +484,42 @@ class TestEdgeSubgraph: assert self.G.graph is self.H.graph -def test_multigraph_add_edges_from_four_tuple_misordered(): - """add_edges_from expects 4-tuples of the format (u, v, key, data_dict). +class CustomDictClass(UserDict): + pass + + +class MultiGraphSubClass(nx.MultiGraph): + node_dict_factory = CustomDictClass # type: ignore + node_attr_dict_factory = CustomDictClass # type: ignore + adjlist_outer_dict_factory = CustomDictClass # type: ignore + adjlist_inner_dict_factory = CustomDictClass # type: ignore + edge_key_dict_factory = CustomDictClass # type: ignore + edge_attr_dict_factory = CustomDictClass # type: ignore + graph_attr_dict_factory = CustomDictClass # type: ignore - Ensure 4-tuples of form (u, v, data_dict, key) raises exception. - """ - G = nx.MultiGraph() - with pytest.raises(TypeError): - # key/data values flipped in 4-tuple - G.add_edges_from([(0, 1, {"color": "red"}, 0)]) + +class TestMultiGraphSubclass(TestMultiGraph): + def setup_method(self): + self.Graph = MultiGraphSubClass + # build K3 + self.k3edges = [(0, 1), (0, 2), (1, 2)] + self.k3nodes = [0, 1, 2] + self.K3 = self.Graph() + self.K3._adj = self.K3.adjlist_outer_dict_factory( + { + 0: self.K3.adjlist_inner_dict_factory(), + 1: self.K3.adjlist_inner_dict_factory(), + 2: self.K3.adjlist_inner_dict_factory(), + } + ) + self.K3._pred = {0: {}, 1: {}, 2: {}} + for u in self.k3nodes: + for v in self.k3nodes: + if u != v: + d = {0: {}} + self.K3._adj[u][v] = d + self.K3._adj[v][u] = d + self.K3._node = self.K3.node_dict_factory() + self.K3._node[0] = self.K3.node_attr_dict_factory() + self.K3._node[1] = self.K3.node_attr_dict_factory() + self.K3._node[2] = self.K3.node_attr_dict_factory() |
