summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMridul Seth <seth.mridul@gmail.com>2022-06-22 12:03:57 +0400
committerJarrod Millman <jarrod.millman@gmail.com>2022-07-18 11:36:27 -0700
commit7425076a30c922923bb7d6d87f18374463b6bfd6 (patch)
tree255149e6cc0d7ea4ae01cd4d487dbd2607e3d026
parent4c9488e57394a56b05c4200268525bd0b8cdafaf (diff)
downloadnetworkx-7425076a30c922923bb7d6d87f18374463b6bfd6.tar.gz
Add more comprehensive tests for pydot (#5792)
* Add more comprehensive tests for pydot * remove the second element from frozenset for cleaner tests Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
-rw-r--r--networkx/drawing/nx_pydot.py10
-rw-r--r--networkx/drawing/tests/test_pydot.py24
2 files changed, 29 insertions, 5 deletions
diff --git a/networkx/drawing/nx_pydot.py b/networkx/drawing/nx_pydot.py
index 45115989..2b01f59f 100644
--- a/networkx/drawing/nx_pydot.py
+++ b/networkx/drawing/nx_pydot.py
@@ -277,8 +277,8 @@ def to_pydot(N):
or _check_colon_quotes(v)
or (
any(
- (_check_colon_quotes(k) or _check_colon_quotes(v))
- for k, v in edgedata.items()
+ (_check_colon_quotes(k) or _check_colon_quotes(val))
+ for k, val in str_edgedata.items()
)
)
)
@@ -293,15 +293,15 @@ def to_pydot(N):
else:
for u, v, edgedata in N.edges(data=True):
- str_edgedata = {k: str(v) for k, v in edgedata.items()}
+ str_edgedata = {str(k): str(v) for k, v in edgedata.items()}
u, v = str(u), str(v)
raise_error = (
_check_colon_quotes(u)
or _check_colon_quotes(v)
or (
any(
- (_check_colon_quotes(k) or _check_colon_quotes(v))
- for k, v in edgedata.items()
+ (_check_colon_quotes(k) or _check_colon_quotes(val))
+ for k, val in str_edgedata.items()
)
)
)
diff --git a/networkx/drawing/tests/test_pydot.py b/networkx/drawing/tests/test_pydot.py
index 134e0112..2e5e3ec6 100644
--- a/networkx/drawing/tests/test_pydot.py
+++ b/networkx/drawing/tests/test_pydot.py
@@ -151,3 +151,27 @@ def test_pydot_issue_258():
G = nx.Graph([('"Example:A"', 1)])
layout = nx.nx_pydot.pydot_layout(G)
assert isinstance(layout, dict)
+
+
+@pytest.mark.parametrize(
+ "graph_type", [nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph]
+)
+def test_hashable_pydot(graph_type):
+ # gh-5790
+ G = graph_type()
+ G.add_edge("5", frozenset([1]), t='"Example:A"', l=False)
+ G.add_edge("1", 2, w=True, t=("node1",), l=frozenset(["node1"]))
+ G.add_edge("node", (3, 3), w="string")
+
+ assert [
+ {"t": '"Example:A"', "l": "False"},
+ {"w": "True", "t": "('node1',)", "l": "frozenset({'node1'})"},
+ {"w": "string"},
+ ] == [
+ attr
+ for _, _, attr in nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).edges.data()
+ ]
+
+ assert {str(i) for i in G.nodes()} == set(
+ nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).nodes
+ )