diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2021-05-18 15:56:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-18 18:56:56 -0400 |
commit | 69b4a686b4064f963f290ac1faa75ee6b0a6ecbc (patch) | |
tree | 39bb5846d8385ad0f51197d6d5c6f658c34c47fd /networkx/readwrite/json_graph/tests/test_tree.py | |
parent | 45bd170c5493347f38616fc3ecbab55fb615a91b (diff) | |
download | networkx-69b4a686b4064f963f290ac1faa75ee6b0a6ecbc.tar.gz |
Remove dictionary from signature of tree_graph and tree_data (#4786)
* Deprecate attrs dict in json_graph.tree fns.
Replace attrs dict in signature with explicit kwargs and
add deprecation warning.
Adds tests that the behavior isn't changed and that warnings are
raised when expected.
* Add deprecations to list and ignore warnings in conftest.
* Modify cytoscape functions attrs deprecation.
* Cleanup cytoscape test suite.
Diffstat (limited to 'networkx/readwrite/json_graph/tests/test_tree.py')
-rw-r--r-- | networkx/readwrite/json_graph/tests/test_tree.py | 86 |
1 files changed, 51 insertions, 35 deletions
diff --git a/networkx/readwrite/json_graph/tests/test_tree.py b/networkx/readwrite/json_graph/tests/test_tree.py index d6aaf958..1912870f 100644 --- a/networkx/readwrite/json_graph/tests/test_tree.py +++ b/networkx/readwrite/json_graph/tests/test_tree.py @@ -4,38 +4,54 @@ import networkx as nx from networkx.readwrite.json_graph import tree_data, tree_graph -class TestTree: - def test_graph(self): - G = nx.DiGraph() - G.add_nodes_from([1, 2, 3], color="red") - G.add_edge(1, 2, foo=7) - G.add_edge(1, 3, foo=10) - G.add_edge(3, 4, foo=10) - H = tree_graph(tree_data(G, 1)) - nx.is_isomorphic(G, H) - - def test_graph_attributes(self): - G = nx.DiGraph() - G.add_nodes_from([1, 2, 3], color="red") - G.add_edge(1, 2, foo=7) - G.add_edge(1, 3, foo=10) - G.add_edge(3, 4, foo=10) - H = tree_graph(tree_data(G, 1)) - assert H.nodes[1]["color"] == "red" - - d = json.dumps(tree_data(G, 1)) - H = tree_graph(json.loads(d)) - assert H.nodes[1]["color"] == "red" - - def test_exception(self): - with pytest.raises(TypeError, match="is not a tree."): - G = nx.complete_graph(3) - tree_data(G, 0) - with pytest.raises(TypeError, match="is not directed."): - G = nx.path_graph(3) - tree_data(G, 0) - with pytest.raises(nx.NetworkXError, match="names are not unique."): - G = nx.MultiDiGraph() - G.add_node(0) - attrs = dict(id="node", children="node") - tree_data(G, 0, attrs) +def test_graph(): + G = nx.DiGraph() + G.add_nodes_from([1, 2, 3], color="red") + G.add_edge(1, 2, foo=7) + G.add_edge(1, 3, foo=10) + G.add_edge(3, 4, foo=10) + H = tree_graph(tree_data(G, 1)) + nx.is_isomorphic(G, H) + + +def test_graph_attributes(): + G = nx.DiGraph() + G.add_nodes_from([1, 2, 3], color="red") + G.add_edge(1, 2, foo=7) + G.add_edge(1, 3, foo=10) + G.add_edge(3, 4, foo=10) + H = tree_graph(tree_data(G, 1)) + assert H.nodes[1]["color"] == "red" + + d = json.dumps(tree_data(G, 1)) + H = tree_graph(json.loads(d)) + assert H.nodes[1]["color"] == "red" + + +def test_exceptions(): + with pytest.raises(TypeError, match="is not a tree."): + G = nx.complete_graph(3) + tree_data(G, 0) + with pytest.raises(TypeError, match="is not directed."): + G = nx.path_graph(3) + tree_data(G, 0) + with pytest.raises(nx.NetworkXError, match="must be different."): + G = nx.MultiDiGraph() + G.add_node(0) + tree_data(G, 0, ident="node", children="node") + + +# NOTE: To be removed when deprecation expires in 3.0 +def test_attrs_deprecation(): + G = nx.path_graph(3, create_using=nx.DiGraph) + # No warnings when `attrs` kwarg not used + with pytest.warns(None) as record: + data = tree_data(G, 0) + H = tree_graph(data) + assert len(record) == 0 + # DeprecationWarning issued when `attrs` is used + attrs = {"id": "foo", "children": "bar"} + with pytest.warns(DeprecationWarning): + data = tree_data(G, 0, attrs=attrs) + with pytest.warns(DeprecationWarning): + H = tree_graph(data, attrs=attrs) |