diff options
-rw-r--r-- | networkx/drawing/nx_pydot.py | 10 | ||||
-rw-r--r-- | networkx/drawing/tests/test_pydot.py | 24 |
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 + ) |