applied-ai-018 commited on
Commit
53756b8
·
verified ·
1 Parent(s): a327798

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/__init__.cpython-310.pyc +0 -0
  2. env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/layout.cpython-310.pyc +0 -0
  3. env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_agraph.cpython-310.pyc +0 -0
  4. env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_latex.cpython-310.pyc +0 -0
  5. env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_pydot.cpython-310.pyc +0 -0
  6. env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_pylab.cpython-310.pyc +0 -0
  7. env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/__init__.py +0 -0
  8. env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/test_agraph.py +240 -0
  9. env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/test_pydot.py +180 -0
  10. env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/test_pylab.py +879 -0
  11. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/__init__.cpython-310.pyc +0 -0
  12. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/atlas.cpython-310.pyc +0 -0
  13. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/classic.cpython-310.pyc +0 -0
  14. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/cographs.cpython-310.pyc +0 -0
  15. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/community.cpython-310.pyc +0 -0
  16. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/degree_seq.cpython-310.pyc +0 -0
  17. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/directed.cpython-310.pyc +0 -0
  18. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/duplication.cpython-310.pyc +0 -0
  19. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/ego.cpython-310.pyc +0 -0
  20. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/expanders.cpython-310.pyc +0 -0
  21. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/geometric.cpython-310.pyc +0 -0
  22. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/harary_graph.cpython-310.pyc +0 -0
  23. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/internet_as_graphs.cpython-310.pyc +0 -0
  24. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/intersection.cpython-310.pyc +0 -0
  25. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/interval_graph.cpython-310.pyc +0 -0
  26. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/joint_degree_seq.cpython-310.pyc +0 -0
  27. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/lattice.cpython-310.pyc +0 -0
  28. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/line.cpython-310.pyc +0 -0
  29. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/mycielski.cpython-310.pyc +0 -0
  30. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/nonisomorphic_trees.cpython-310.pyc +0 -0
  31. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/random_clustered.cpython-310.pyc +0 -0
  32. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/random_graphs.cpython-310.pyc +0 -0
  33. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/small.cpython-310.pyc +0 -0
  34. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/social.cpython-310.pyc +0 -0
  35. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/spectral_graph_forge.cpython-310.pyc +0 -0
  36. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/stochastic.cpython-310.pyc +0 -0
  37. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/sudoku.cpython-310.pyc +0 -0
  38. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/time_series.cpython-310.pyc +0 -0
  39. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/trees.cpython-310.pyc +0 -0
  40. env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/triads.cpython-310.pyc +0 -0
  41. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/__init__.cpython-310.pyc +0 -0
  42. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_atlas.cpython-310.pyc +0 -0
  43. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_classic.cpython-310.pyc +0 -0
  44. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_cographs.cpython-310.pyc +0 -0
  45. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_community.cpython-310.pyc +0 -0
  46. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_degree_seq.cpython-310.pyc +0 -0
  47. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_directed.cpython-310.pyc +0 -0
  48. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_duplication.cpython-310.pyc +0 -0
  49. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_ego.cpython-310.pyc +0 -0
  50. env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_expanders.cpython-310.pyc +0 -0
env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (309 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/layout.cpython-310.pyc ADDED
Binary file (33.7 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_agraph.cpython-310.pyc ADDED
Binary file (12.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_latex.cpython-310.pyc ADDED
Binary file (22.2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_pydot.cpython-310.pyc ADDED
Binary file (10 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/drawing/__pycache__/nx_pylab.cpython-310.pyc ADDED
Binary file (51.6 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/__init__.py ADDED
File without changes
env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/test_agraph.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for PyGraphviz interface."""
2
+ import warnings
3
+
4
+ import pytest
5
+
6
+ pygraphviz = pytest.importorskip("pygraphviz")
7
+
8
+
9
+ import networkx as nx
10
+ from networkx.utils import edges_equal, graphs_equal, nodes_equal
11
+
12
+
13
+ class TestAGraph:
14
+ def build_graph(self, G):
15
+ edges = [("A", "B"), ("A", "C"), ("A", "C"), ("B", "C"), ("A", "D")]
16
+ G.add_edges_from(edges)
17
+ G.add_node("E")
18
+ G.graph["metal"] = "bronze"
19
+ return G
20
+
21
+ def assert_equal(self, G1, G2):
22
+ assert nodes_equal(G1.nodes(), G2.nodes())
23
+ assert edges_equal(G1.edges(), G2.edges())
24
+ assert G1.graph["metal"] == G2.graph["metal"]
25
+
26
+ @pytest.mark.parametrize(
27
+ "G", (nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph())
28
+ )
29
+ def test_agraph_roundtripping(self, G, tmp_path):
30
+ G = self.build_graph(G)
31
+ A = nx.nx_agraph.to_agraph(G)
32
+ H = nx.nx_agraph.from_agraph(A)
33
+ self.assert_equal(G, H)
34
+
35
+ fname = tmp_path / "test.dot"
36
+ nx.drawing.nx_agraph.write_dot(H, fname)
37
+ Hin = nx.nx_agraph.read_dot(fname)
38
+ self.assert_equal(H, Hin)
39
+
40
+ fname = tmp_path / "fh_test.dot"
41
+ with open(fname, "w") as fh:
42
+ nx.drawing.nx_agraph.write_dot(H, fh)
43
+
44
+ with open(fname) as fh:
45
+ Hin = nx.nx_agraph.read_dot(fh)
46
+ self.assert_equal(H, Hin)
47
+
48
+ def test_from_agraph_name(self):
49
+ G = nx.Graph(name="test")
50
+ A = nx.nx_agraph.to_agraph(G)
51
+ H = nx.nx_agraph.from_agraph(A)
52
+ assert G.name == "test"
53
+
54
+ @pytest.mark.parametrize(
55
+ "graph_class", (nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph)
56
+ )
57
+ def test_from_agraph_create_using(self, graph_class):
58
+ G = nx.path_graph(3)
59
+ A = nx.nx_agraph.to_agraph(G)
60
+ H = nx.nx_agraph.from_agraph(A, create_using=graph_class)
61
+ assert isinstance(H, graph_class)
62
+
63
+ def test_from_agraph_named_edges(self):
64
+ # Create an AGraph from an existing (non-multi) Graph
65
+ G = nx.Graph()
66
+ G.add_nodes_from([0, 1])
67
+ A = nx.nx_agraph.to_agraph(G)
68
+ # Add edge (+ name, given by key) to the AGraph
69
+ A.add_edge(0, 1, key="foo")
70
+ # Verify a.name roundtrips out to 'key' in from_agraph
71
+ H = nx.nx_agraph.from_agraph(A)
72
+ assert isinstance(H, nx.Graph)
73
+ assert ("0", "1", {"key": "foo"}) in H.edges(data=True)
74
+
75
+ def test_to_agraph_with_nodedata(self):
76
+ G = nx.Graph()
77
+ G.add_node(1, color="red")
78
+ A = nx.nx_agraph.to_agraph(G)
79
+ assert dict(A.nodes()[0].attr) == {"color": "red"}
80
+
81
+ @pytest.mark.parametrize("graph_class", (nx.Graph, nx.MultiGraph))
82
+ def test_to_agraph_with_edgedata(self, graph_class):
83
+ G = graph_class()
84
+ G.add_nodes_from([0, 1])
85
+ G.add_edge(0, 1, color="yellow")
86
+ A = nx.nx_agraph.to_agraph(G)
87
+ assert dict(A.edges()[0].attr) == {"color": "yellow"}
88
+
89
+ def test_view_pygraphviz_path(self, tmp_path):
90
+ G = nx.complete_graph(3)
91
+ input_path = str(tmp_path / "graph.png")
92
+ out_path, A = nx.nx_agraph.view_pygraphviz(G, path=input_path, show=False)
93
+ assert out_path == input_path
94
+ # Ensure file is not empty
95
+ with open(input_path, "rb") as fh:
96
+ data = fh.read()
97
+ assert len(data) > 0
98
+
99
+ def test_view_pygraphviz_file_suffix(self, tmp_path):
100
+ G = nx.complete_graph(3)
101
+ path, A = nx.nx_agraph.view_pygraphviz(G, suffix=1, show=False)
102
+ assert path[-6:] == "_1.png"
103
+
104
+ def test_view_pygraphviz(self):
105
+ G = nx.Graph() # "An empty graph cannot be drawn."
106
+ pytest.raises(nx.NetworkXException, nx.nx_agraph.view_pygraphviz, G)
107
+ G = nx.barbell_graph(4, 6)
108
+ nx.nx_agraph.view_pygraphviz(G, show=False)
109
+
110
+ def test_view_pygraphviz_edgelabel(self):
111
+ G = nx.Graph()
112
+ G.add_edge(1, 2, weight=7)
113
+ G.add_edge(2, 3, weight=8)
114
+ path, A = nx.nx_agraph.view_pygraphviz(G, edgelabel="weight", show=False)
115
+ for edge in A.edges():
116
+ assert edge.attr["weight"] in ("7", "8")
117
+
118
+ def test_view_pygraphviz_callable_edgelabel(self):
119
+ G = nx.complete_graph(3)
120
+
121
+ def foo_label(data):
122
+ return "foo"
123
+
124
+ path, A = nx.nx_agraph.view_pygraphviz(G, edgelabel=foo_label, show=False)
125
+ for edge in A.edges():
126
+ assert edge.attr["label"] == "foo"
127
+
128
+ def test_view_pygraphviz_multigraph_edgelabels(self):
129
+ G = nx.MultiGraph()
130
+ G.add_edge(0, 1, key=0, name="left_fork")
131
+ G.add_edge(0, 1, key=1, name="right_fork")
132
+ path, A = nx.nx_agraph.view_pygraphviz(G, edgelabel="name", show=False)
133
+ edges = A.edges()
134
+ assert len(edges) == 2
135
+ for edge in edges:
136
+ assert edge.attr["label"].strip() in ("left_fork", "right_fork")
137
+
138
+ def test_graph_with_reserved_keywords(self):
139
+ # test attribute/keyword clash case for #1582
140
+ # node: n
141
+ # edges: u,v
142
+ G = nx.Graph()
143
+ G = self.build_graph(G)
144
+ G.nodes["E"]["n"] = "keyword"
145
+ G.edges[("A", "B")]["u"] = "keyword"
146
+ G.edges[("A", "B")]["v"] = "keyword"
147
+ A = nx.nx_agraph.to_agraph(G)
148
+
149
+ def test_view_pygraphviz_no_added_attrs_to_input(self):
150
+ G = nx.complete_graph(2)
151
+ path, A = nx.nx_agraph.view_pygraphviz(G, show=False)
152
+ assert G.graph == {}
153
+
154
+ @pytest.mark.xfail(reason="known bug in clean_attrs")
155
+ def test_view_pygraphviz_leaves_input_graph_unmodified(self):
156
+ G = nx.complete_graph(2)
157
+ # Add entries to graph dict that to_agraph handles specially
158
+ G.graph["node"] = {"width": "0.80"}
159
+ G.graph["edge"] = {"fontsize": "14"}
160
+ path, A = nx.nx_agraph.view_pygraphviz(G, show=False)
161
+ assert G.graph == {"node": {"width": "0.80"}, "edge": {"fontsize": "14"}}
162
+
163
+ def test_graph_with_AGraph_attrs(self):
164
+ G = nx.complete_graph(2)
165
+ # Add entries to graph dict that to_agraph handles specially
166
+ G.graph["node"] = {"width": "0.80"}
167
+ G.graph["edge"] = {"fontsize": "14"}
168
+ path, A = nx.nx_agraph.view_pygraphviz(G, show=False)
169
+ # Ensure user-specified values are not lost
170
+ assert dict(A.node_attr)["width"] == "0.80"
171
+ assert dict(A.edge_attr)["fontsize"] == "14"
172
+
173
+ def test_round_trip_empty_graph(self):
174
+ G = nx.Graph()
175
+ A = nx.nx_agraph.to_agraph(G)
176
+ H = nx.nx_agraph.from_agraph(A)
177
+ # assert graphs_equal(G, H)
178
+ AA = nx.nx_agraph.to_agraph(H)
179
+ HH = nx.nx_agraph.from_agraph(AA)
180
+ assert graphs_equal(H, HH)
181
+ G.graph["graph"] = {}
182
+ G.graph["node"] = {}
183
+ G.graph["edge"] = {}
184
+ assert graphs_equal(G, HH)
185
+
186
+ @pytest.mark.xfail(reason="integer->string node conversion in round trip")
187
+ def test_round_trip_integer_nodes(self):
188
+ G = nx.complete_graph(3)
189
+ A = nx.nx_agraph.to_agraph(G)
190
+ H = nx.nx_agraph.from_agraph(A)
191
+ assert graphs_equal(G, H)
192
+
193
+ def test_graphviz_alias(self):
194
+ G = self.build_graph(nx.Graph())
195
+ pos_graphviz = nx.nx_agraph.graphviz_layout(G)
196
+ pos_pygraphviz = nx.nx_agraph.pygraphviz_layout(G)
197
+ assert pos_graphviz == pos_pygraphviz
198
+
199
+ @pytest.mark.parametrize("root", range(5))
200
+ def test_pygraphviz_layout_root(self, root):
201
+ # NOTE: test depends on layout prog being deterministic
202
+ G = nx.complete_graph(5)
203
+ A = nx.nx_agraph.to_agraph(G)
204
+ # Get layout with root arg is not None
205
+ pygv_layout = nx.nx_agraph.pygraphviz_layout(G, prog="circo", root=root)
206
+ # Equivalent layout directly on AGraph
207
+ A.layout(args=f"-Groot={root}", prog="circo")
208
+ # Parse AGraph layout
209
+ a1_pos = tuple(float(v) for v in dict(A.get_node("1").attr)["pos"].split(","))
210
+ assert pygv_layout[1] == a1_pos
211
+
212
+ def test_2d_layout(self):
213
+ G = nx.Graph()
214
+ G = self.build_graph(G)
215
+ G.graph["dimen"] = 2
216
+ pos = nx.nx_agraph.pygraphviz_layout(G, prog="neato")
217
+ pos = list(pos.values())
218
+ assert len(pos) == 5
219
+ assert len(pos[0]) == 2
220
+
221
+ def test_3d_layout(self):
222
+ G = nx.Graph()
223
+ G = self.build_graph(G)
224
+ G.graph["dimen"] = 3
225
+ pos = nx.nx_agraph.pygraphviz_layout(G, prog="neato")
226
+ pos = list(pos.values())
227
+ assert len(pos) == 5
228
+ assert len(pos[0]) == 3
229
+
230
+ def test_no_warnings_raised(self):
231
+ # Test that no warnings are raised when Networkx graph
232
+ # is converted to Pygraphviz graph and 'pos'
233
+ # attribute is given
234
+ G = nx.Graph()
235
+ G.add_node(0, pos=(0, 0))
236
+ G.add_node(1, pos=(1, 1))
237
+ A = nx.nx_agraph.to_agraph(G)
238
+ with warnings.catch_warnings(record=True) as record:
239
+ A.layout()
240
+ assert len(record) == 0
env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/test_pydot.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for pydot drawing functions."""
2
+ from io import StringIO
3
+
4
+ import pytest
5
+
6
+ import networkx as nx
7
+ from networkx.utils import graphs_equal
8
+
9
+ pydot = pytest.importorskip("pydot")
10
+
11
+
12
+ class TestPydot:
13
+ @pytest.mark.parametrize("G", (nx.Graph(), nx.DiGraph()))
14
+ @pytest.mark.parametrize("prog", ("neato", "dot"))
15
+ def test_pydot(self, G, prog, tmp_path):
16
+ """
17
+ Validate :mod:`pydot`-based usage of the passed NetworkX graph with the
18
+ passed basename of an external GraphViz command (e.g., `dot`, `neato`).
19
+ """
20
+
21
+ # Set the name of this graph to... "G". Failing to do so will
22
+ # subsequently trip an assertion expecting this name.
23
+ G.graph["name"] = "G"
24
+
25
+ # Add arbitrary nodes and edges to the passed empty graph.
26
+ G.add_edges_from([("A", "B"), ("A", "C"), ("B", "C"), ("A", "D")])
27
+ G.add_node("E")
28
+
29
+ # Validate layout of this graph with the passed GraphViz command.
30
+ graph_layout = nx.nx_pydot.pydot_layout(G, prog=prog)
31
+ assert isinstance(graph_layout, dict)
32
+
33
+ # Convert this graph into a "pydot.Dot" instance.
34
+ P = nx.nx_pydot.to_pydot(G)
35
+
36
+ # Convert this "pydot.Dot" instance back into a graph of the same type.
37
+ G2 = G.__class__(nx.nx_pydot.from_pydot(P))
38
+
39
+ # Validate the original and resulting graphs to be the same.
40
+ assert graphs_equal(G, G2)
41
+
42
+ fname = tmp_path / "out.dot"
43
+
44
+ # Serialize this "pydot.Dot" instance to a temporary file in dot format
45
+ P.write_raw(fname)
46
+
47
+ # Deserialize a list of new "pydot.Dot" instances back from this file.
48
+ Pin_list = pydot.graph_from_dot_file(path=fname, encoding="utf-8")
49
+
50
+ # Validate this file to contain only one graph.
51
+ assert len(Pin_list) == 1
52
+
53
+ # The single "pydot.Dot" instance deserialized from this file.
54
+ Pin = Pin_list[0]
55
+
56
+ # Sorted list of all nodes in the original "pydot.Dot" instance.
57
+ n1 = sorted(p.get_name() for p in P.get_node_list())
58
+
59
+ # Sorted list of all nodes in the deserialized "pydot.Dot" instance.
60
+ n2 = sorted(p.get_name() for p in Pin.get_node_list())
61
+
62
+ # Validate these instances to contain the same nodes.
63
+ assert n1 == n2
64
+
65
+ # Sorted list of all edges in the original "pydot.Dot" instance.
66
+ e1 = sorted((e.get_source(), e.get_destination()) for e in P.get_edge_list())
67
+
68
+ # Sorted list of all edges in the original "pydot.Dot" instance.
69
+ e2 = sorted((e.get_source(), e.get_destination()) for e in Pin.get_edge_list())
70
+
71
+ # Validate these instances to contain the same edges.
72
+ assert e1 == e2
73
+
74
+ # Deserialize a new graph of the same type back from this file.
75
+ Hin = nx.nx_pydot.read_dot(fname)
76
+ Hin = G.__class__(Hin)
77
+
78
+ # Validate the original and resulting graphs to be the same.
79
+ assert graphs_equal(G, Hin)
80
+
81
+ def test_read_write(self):
82
+ G = nx.MultiGraph()
83
+ G.graph["name"] = "G"
84
+ G.add_edge("1", "2", key="0") # read assumes strings
85
+ fh = StringIO()
86
+ nx.nx_pydot.write_dot(G, fh)
87
+ fh.seek(0)
88
+ H = nx.nx_pydot.read_dot(fh)
89
+ assert graphs_equal(G, H)
90
+
91
+
92
+ def test_pydot_issue_258():
93
+ G = nx.Graph([("Example:A", 1)])
94
+ with pytest.raises(ValueError):
95
+ nx.nx_pydot.to_pydot(G)
96
+ with pytest.raises(ValueError):
97
+ nx.nx_pydot.pydot_layout(G)
98
+
99
+ G = nx.Graph()
100
+ G.add_node("1.2", style="filled", fillcolor="red:yellow")
101
+ with pytest.raises(ValueError):
102
+ nx.nx_pydot.to_pydot(G)
103
+ G.remove_node("1.2")
104
+ G.add_node("1.2", style="filled", fillcolor='"red:yellow"')
105
+ assert (
106
+ G.nodes.data() == nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).nodes.data()
107
+ )
108
+
109
+ G = nx.DiGraph()
110
+ G.add_edge("1", "2", foo="bar:1")
111
+ with pytest.raises(ValueError):
112
+ nx.nx_pydot.to_pydot(G)
113
+ G = nx.DiGraph()
114
+ G.add_edge("1", "2", foo='"bar:1"')
115
+ assert G["1"]["2"] == nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G))["1"]["2"]
116
+
117
+ G = nx.MultiGraph()
118
+ G.add_edge("1", "2", foo="b:1")
119
+ G.add_edge("1", "2", bar="foo:foo")
120
+ with pytest.raises(ValueError):
121
+ nx.nx_pydot.to_pydot(G)
122
+ G = nx.MultiGraph()
123
+ G.add_edge("1", "2", foo='"b:1"')
124
+ G.add_edge("1", "2", bar='"foo:foo"')
125
+ # Keys as integers aren't preserved in the conversion. They are read as strings.
126
+ assert [attr for _, _, attr in G.edges.data()] == [
127
+ attr
128
+ for _, _, attr in nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).edges.data()
129
+ ]
130
+
131
+ G = nx.Graph()
132
+ G.add_edge("1", "2")
133
+ G["1"]["2"]["f:oo"] = "bar"
134
+ with pytest.raises(ValueError):
135
+ nx.nx_pydot.to_pydot(G)
136
+ G = nx.Graph()
137
+ G.add_edge("1", "2")
138
+ G["1"]["2"]['"f:oo"'] = "bar"
139
+ assert G["1"]["2"] == nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G))["1"]["2"]
140
+
141
+ G = nx.Graph([('"Example:A"', 1)])
142
+ layout = nx.nx_pydot.pydot_layout(G)
143
+ assert isinstance(layout, dict)
144
+
145
+
146
+ @pytest.mark.parametrize(
147
+ "graph_type", [nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph]
148
+ )
149
+ def test_hashable_pydot(graph_type):
150
+ # gh-5790
151
+ G = graph_type()
152
+ G.add_edge("5", frozenset([1]), t='"Example:A"', l=False)
153
+ G.add_edge("1", 2, w=True, t=("node1",), l=frozenset(["node1"]))
154
+ G.add_edge("node", (3, 3), w="string")
155
+
156
+ assert [
157
+ {"t": '"Example:A"', "l": "False"},
158
+ {"w": "True", "t": "('node1',)", "l": "frozenset({'node1'})"},
159
+ {"w": "string"},
160
+ ] == [
161
+ attr
162
+ for _, _, attr in nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).edges.data()
163
+ ]
164
+
165
+ assert {str(i) for i in G.nodes()} == set(
166
+ nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).nodes
167
+ )
168
+
169
+
170
+ def test_pydot_numerical_name():
171
+ G = nx.Graph()
172
+ G.add_edges_from([("A", "B"), (0, 1)])
173
+ graph_layout = nx.nx_pydot.pydot_layout(G, prog="dot")
174
+ assert isinstance(graph_layout, dict)
175
+ assert "0" not in graph_layout
176
+ assert 0 in graph_layout
177
+ assert "1" not in graph_layout
178
+ assert 1 in graph_layout
179
+ assert "A" in graph_layout
180
+ assert "B" in graph_layout
env-llmeval/lib/python3.10/site-packages/networkx/drawing/tests/test_pylab.py ADDED
@@ -0,0 +1,879 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for matplotlib drawing functions."""
2
+ import itertools
3
+ import os
4
+ import warnings
5
+
6
+ import pytest
7
+
8
+ mpl = pytest.importorskip("matplotlib")
9
+ np = pytest.importorskip("numpy")
10
+ mpl.use("PS")
11
+ plt = pytest.importorskip("matplotlib.pyplot")
12
+ plt.rcParams["text.usetex"] = False
13
+
14
+
15
+ import networkx as nx
16
+
17
+ barbell = nx.barbell_graph(4, 6)
18
+
19
+
20
+ def test_draw():
21
+ try:
22
+ functions = [
23
+ nx.draw_circular,
24
+ nx.draw_kamada_kawai,
25
+ nx.draw_planar,
26
+ nx.draw_random,
27
+ nx.draw_spectral,
28
+ nx.draw_spring,
29
+ nx.draw_shell,
30
+ ]
31
+ options = [{"node_color": "black", "node_size": 100, "width": 3}]
32
+ for function, option in itertools.product(functions, options):
33
+ function(barbell, **option)
34
+ plt.savefig("test.ps")
35
+ except ModuleNotFoundError: # draw_kamada_kawai requires scipy
36
+ pass
37
+ finally:
38
+ try:
39
+ os.unlink("test.ps")
40
+ except OSError:
41
+ pass
42
+
43
+
44
+ def test_draw_shell_nlist():
45
+ try:
46
+ nlist = [list(range(4)), list(range(4, 10)), list(range(10, 14))]
47
+ nx.draw_shell(barbell, nlist=nlist)
48
+ plt.savefig("test.ps")
49
+ finally:
50
+ try:
51
+ os.unlink("test.ps")
52
+ except OSError:
53
+ pass
54
+
55
+
56
+ def test_edge_colormap():
57
+ colors = range(barbell.number_of_edges())
58
+ nx.draw_spring(
59
+ barbell, edge_color=colors, width=4, edge_cmap=plt.cm.Blues, with_labels=True
60
+ )
61
+ # plt.show()
62
+
63
+
64
+ def test_arrows():
65
+ nx.draw_spring(barbell.to_directed())
66
+ # plt.show()
67
+
68
+
69
+ @pytest.mark.parametrize(
70
+ ("edge_color", "expected"),
71
+ (
72
+ (None, "black"), # Default
73
+ ("r", "red"), # Non-default color string
74
+ (["r"], "red"), # Single non-default color in a list
75
+ ((1.0, 1.0, 0.0), "yellow"), # single color as rgb tuple
76
+ ([(1.0, 1.0, 0.0)], "yellow"), # single color as rgb tuple in list
77
+ ((0, 1, 0, 1), "lime"), # single color as rgba tuple
78
+ ([(0, 1, 0, 1)], "lime"), # single color as rgba tuple in list
79
+ ("#0000ff", "blue"), # single color hex code
80
+ (["#0000ff"], "blue"), # hex code in list
81
+ ),
82
+ )
83
+ @pytest.mark.parametrize("edgelist", (None, [(0, 1)]))
84
+ def test_single_edge_color_undirected(edge_color, expected, edgelist):
85
+ """Tests ways of specifying all edges have a single color for edges
86
+ drawn with a LineCollection"""
87
+
88
+ G = nx.path_graph(3)
89
+ drawn_edges = nx.draw_networkx_edges(
90
+ G, pos=nx.random_layout(G), edgelist=edgelist, edge_color=edge_color
91
+ )
92
+ assert mpl.colors.same_color(drawn_edges.get_color(), expected)
93
+
94
+
95
+ @pytest.mark.parametrize(
96
+ ("edge_color", "expected"),
97
+ (
98
+ (None, "black"), # Default
99
+ ("r", "red"), # Non-default color string
100
+ (["r"], "red"), # Single non-default color in a list
101
+ ((1.0, 1.0, 0.0), "yellow"), # single color as rgb tuple
102
+ ([(1.0, 1.0, 0.0)], "yellow"), # single color as rgb tuple in list
103
+ ((0, 1, 0, 1), "lime"), # single color as rgba tuple
104
+ ([(0, 1, 0, 1)], "lime"), # single color as rgba tuple in list
105
+ ("#0000ff", "blue"), # single color hex code
106
+ (["#0000ff"], "blue"), # hex code in list
107
+ ),
108
+ )
109
+ @pytest.mark.parametrize("edgelist", (None, [(0, 1)]))
110
+ def test_single_edge_color_directed(edge_color, expected, edgelist):
111
+ """Tests ways of specifying all edges have a single color for edges drawn
112
+ with FancyArrowPatches"""
113
+
114
+ G = nx.path_graph(3, create_using=nx.DiGraph)
115
+ drawn_edges = nx.draw_networkx_edges(
116
+ G, pos=nx.random_layout(G), edgelist=edgelist, edge_color=edge_color
117
+ )
118
+ for fap in drawn_edges:
119
+ assert mpl.colors.same_color(fap.get_edgecolor(), expected)
120
+
121
+
122
+ def test_edge_color_tuple_interpretation():
123
+ """If edge_color is a sequence with the same length as edgelist, then each
124
+ value in edge_color is mapped onto each edge via colormap."""
125
+ G = nx.path_graph(6, create_using=nx.DiGraph)
126
+ pos = {n: (n, n) for n in range(len(G))}
127
+
128
+ # num edges != 3 or 4 --> edge_color interpreted as rgb(a)
129
+ for ec in ((0, 0, 1), (0, 0, 1, 1)):
130
+ # More than 4 edges
131
+ drawn_edges = nx.draw_networkx_edges(G, pos, edge_color=ec)
132
+ for fap in drawn_edges:
133
+ assert mpl.colors.same_color(fap.get_edgecolor(), ec)
134
+ # Fewer than 3 edges
135
+ drawn_edges = nx.draw_networkx_edges(
136
+ G, pos, edgelist=[(0, 1), (1, 2)], edge_color=ec
137
+ )
138
+ for fap in drawn_edges:
139
+ assert mpl.colors.same_color(fap.get_edgecolor(), ec)
140
+
141
+ # num edges == 3, len(edge_color) == 4: interpreted as rgba
142
+ drawn_edges = nx.draw_networkx_edges(
143
+ G, pos, edgelist=[(0, 1), (1, 2), (2, 3)], edge_color=(0, 0, 1, 1)
144
+ )
145
+ for fap in drawn_edges:
146
+ assert mpl.colors.same_color(fap.get_edgecolor(), "blue")
147
+
148
+ # num edges == 4, len(edge_color) == 3: interpreted as rgb
149
+ drawn_edges = nx.draw_networkx_edges(
150
+ G, pos, edgelist=[(0, 1), (1, 2), (2, 3), (3, 4)], edge_color=(0, 0, 1)
151
+ )
152
+ for fap in drawn_edges:
153
+ assert mpl.colors.same_color(fap.get_edgecolor(), "blue")
154
+
155
+ # num edges == len(edge_color) == 3: interpreted with cmap, *not* as rgb
156
+ drawn_edges = nx.draw_networkx_edges(
157
+ G, pos, edgelist=[(0, 1), (1, 2), (2, 3)], edge_color=(0, 0, 1)
158
+ )
159
+ assert mpl.colors.same_color(
160
+ drawn_edges[0].get_edgecolor(), drawn_edges[1].get_edgecolor()
161
+ )
162
+ for fap in drawn_edges:
163
+ assert not mpl.colors.same_color(fap.get_edgecolor(), "blue")
164
+
165
+ # num edges == len(edge_color) == 4: interpreted with cmap, *not* as rgba
166
+ drawn_edges = nx.draw_networkx_edges(
167
+ G, pos, edgelist=[(0, 1), (1, 2), (2, 3), (3, 4)], edge_color=(0, 0, 1, 1)
168
+ )
169
+ assert mpl.colors.same_color(
170
+ drawn_edges[0].get_edgecolor(), drawn_edges[1].get_edgecolor()
171
+ )
172
+ assert mpl.colors.same_color(
173
+ drawn_edges[2].get_edgecolor(), drawn_edges[3].get_edgecolor()
174
+ )
175
+ for fap in drawn_edges:
176
+ assert not mpl.colors.same_color(fap.get_edgecolor(), "blue")
177
+
178
+
179
+ def test_fewer_edge_colors_than_num_edges_directed():
180
+ """Test that the edge colors are cycled when there are fewer specified
181
+ colors than edges."""
182
+ G = barbell.to_directed()
183
+ pos = nx.random_layout(barbell)
184
+ edgecolors = ("r", "g", "b")
185
+ drawn_edges = nx.draw_networkx_edges(G, pos, edge_color=edgecolors)
186
+ for fap, expected in zip(drawn_edges, itertools.cycle(edgecolors)):
187
+ assert mpl.colors.same_color(fap.get_edgecolor(), expected)
188
+
189
+
190
+ def test_more_edge_colors_than_num_edges_directed():
191
+ """Test that extra edge colors are ignored when there are more specified
192
+ colors than edges."""
193
+ G = nx.path_graph(4, create_using=nx.DiGraph) # 3 edges
194
+ pos = nx.random_layout(barbell)
195
+ edgecolors = ("r", "g", "b", "c") # 4 edge colors
196
+ drawn_edges = nx.draw_networkx_edges(G, pos, edge_color=edgecolors)
197
+ for fap, expected in zip(drawn_edges, edgecolors[:-1]):
198
+ assert mpl.colors.same_color(fap.get_edgecolor(), expected)
199
+
200
+
201
+ def test_edge_color_string_with_global_alpha_undirected():
202
+ edge_collection = nx.draw_networkx_edges(
203
+ barbell,
204
+ pos=nx.random_layout(barbell),
205
+ edgelist=[(0, 1), (1, 2)],
206
+ edge_color="purple",
207
+ alpha=0.2,
208
+ )
209
+ ec = edge_collection.get_color().squeeze() # as rgba tuple
210
+ assert len(edge_collection.get_paths()) == 2
211
+ assert mpl.colors.same_color(ec[:-1], "purple")
212
+ assert ec[-1] == 0.2
213
+
214
+
215
+ def test_edge_color_string_with_global_alpha_directed():
216
+ drawn_edges = nx.draw_networkx_edges(
217
+ barbell.to_directed(),
218
+ pos=nx.random_layout(barbell),
219
+ edgelist=[(0, 1), (1, 2)],
220
+ edge_color="purple",
221
+ alpha=0.2,
222
+ )
223
+ assert len(drawn_edges) == 2
224
+ for fap in drawn_edges:
225
+ ec = fap.get_edgecolor() # As rgba tuple
226
+ assert mpl.colors.same_color(ec[:-1], "purple")
227
+ assert ec[-1] == 0.2
228
+
229
+
230
+ @pytest.mark.parametrize("graph_type", (nx.Graph, nx.DiGraph))
231
+ def test_edge_width_default_value(graph_type):
232
+ """Test the default linewidth for edges drawn either via LineCollection or
233
+ FancyArrowPatches."""
234
+ G = nx.path_graph(2, create_using=graph_type)
235
+ pos = {n: (n, n) for n in range(len(G))}
236
+ drawn_edges = nx.draw_networkx_edges(G, pos)
237
+ if isinstance(drawn_edges, list): # directed case: list of FancyArrowPatch
238
+ drawn_edges = drawn_edges[0]
239
+ assert drawn_edges.get_linewidth() == 1
240
+
241
+
242
+ @pytest.mark.parametrize(
243
+ ("edgewidth", "expected"),
244
+ (
245
+ (3, 3), # single-value, non-default
246
+ ([3], 3), # Single value as a list
247
+ ),
248
+ )
249
+ def test_edge_width_single_value_undirected(edgewidth, expected):
250
+ G = nx.path_graph(4)
251
+ pos = {n: (n, n) for n in range(len(G))}
252
+ drawn_edges = nx.draw_networkx_edges(G, pos, width=edgewidth)
253
+ assert len(drawn_edges.get_paths()) == 3
254
+ assert drawn_edges.get_linewidth() == expected
255
+
256
+
257
+ @pytest.mark.parametrize(
258
+ ("edgewidth", "expected"),
259
+ (
260
+ (3, 3), # single-value, non-default
261
+ ([3], 3), # Single value as a list
262
+ ),
263
+ )
264
+ def test_edge_width_single_value_directed(edgewidth, expected):
265
+ G = nx.path_graph(4, create_using=nx.DiGraph)
266
+ pos = {n: (n, n) for n in range(len(G))}
267
+ drawn_edges = nx.draw_networkx_edges(G, pos, width=edgewidth)
268
+ assert len(drawn_edges) == 3
269
+ for fap in drawn_edges:
270
+ assert fap.get_linewidth() == expected
271
+
272
+
273
+ @pytest.mark.parametrize(
274
+ "edgelist",
275
+ (
276
+ [(0, 1), (1, 2), (2, 3)], # one width specification per edge
277
+ None, # fewer widths than edges - widths cycle
278
+ [(0, 1), (1, 2)], # More widths than edges - unused widths ignored
279
+ ),
280
+ )
281
+ def test_edge_width_sequence(edgelist):
282
+ G = barbell.to_directed()
283
+ pos = nx.random_layout(G)
284
+ widths = (0.5, 2.0, 12.0)
285
+ drawn_edges = nx.draw_networkx_edges(G, pos, edgelist=edgelist, width=widths)
286
+ for fap, expected_width in zip(drawn_edges, itertools.cycle(widths)):
287
+ assert fap.get_linewidth() == expected_width
288
+
289
+
290
+ def test_edge_color_with_edge_vmin_vmax():
291
+ """Test that edge_vmin and edge_vmax properly set the dynamic range of the
292
+ color map when num edges == len(edge_colors)."""
293
+ G = nx.path_graph(3, create_using=nx.DiGraph)
294
+ pos = nx.random_layout(G)
295
+ # Extract colors from the original (unscaled) colormap
296
+ drawn_edges = nx.draw_networkx_edges(G, pos, edge_color=[0, 1.0])
297
+ orig_colors = [e.get_edgecolor() for e in drawn_edges]
298
+ # Colors from scaled colormap
299
+ drawn_edges = nx.draw_networkx_edges(
300
+ G, pos, edge_color=[0.2, 0.8], edge_vmin=0.2, edge_vmax=0.8
301
+ )
302
+ scaled_colors = [e.get_edgecolor() for e in drawn_edges]
303
+ assert mpl.colors.same_color(orig_colors, scaled_colors)
304
+
305
+
306
+ def test_directed_edges_linestyle_default():
307
+ """Test default linestyle for edges drawn with FancyArrowPatches."""
308
+ G = nx.path_graph(4, create_using=nx.DiGraph) # Graph with 3 edges
309
+ pos = {n: (n, n) for n in range(len(G))}
310
+
311
+ # edge with default style
312
+ drawn_edges = nx.draw_networkx_edges(G, pos)
313
+ assert len(drawn_edges) == 3
314
+ for fap in drawn_edges:
315
+ assert fap.get_linestyle() == "solid"
316
+
317
+
318
+ @pytest.mark.parametrize(
319
+ "style",
320
+ (
321
+ "dashed", # edge with string style
322
+ "--", # edge with simplified string style
323
+ (1, (1, 1)), # edge with (offset, onoffseq) style
324
+ ),
325
+ )
326
+ def test_directed_edges_linestyle_single_value(style):
327
+ """Tests support for specifying linestyles with a single value to be applied to
328
+ all edges in ``draw_networkx_edges`` for FancyArrowPatch outputs
329
+ (e.g. directed edges)."""
330
+
331
+ G = nx.path_graph(4, create_using=nx.DiGraph) # Graph with 3 edges
332
+ pos = {n: (n, n) for n in range(len(G))}
333
+
334
+ drawn_edges = nx.draw_networkx_edges(G, pos, style=style)
335
+ assert len(drawn_edges) == 3
336
+ for fap in drawn_edges:
337
+ assert fap.get_linestyle() == style
338
+
339
+
340
+ @pytest.mark.parametrize(
341
+ "style_seq",
342
+ (
343
+ ["dashed"], # edge with string style in list
344
+ ["--"], # edge with simplified string style in list
345
+ [(1, (1, 1))], # edge with (offset, onoffseq) style in list
346
+ ["--", "-", ":"], # edges with styles for each edge
347
+ ["--", "-"], # edges with fewer styles than edges (styles cycle)
348
+ ["--", "-", ":", "-."], # edges with more styles than edges (extra unused)
349
+ ),
350
+ )
351
+ def test_directed_edges_linestyle_sequence(style_seq):
352
+ """Tests support for specifying linestyles with sequences in
353
+ ``draw_networkx_edges`` for FancyArrowPatch outputs (e.g. directed edges)."""
354
+
355
+ G = nx.path_graph(4, create_using=nx.DiGraph) # Graph with 3 edges
356
+ pos = {n: (n, n) for n in range(len(G))}
357
+
358
+ drawn_edges = nx.draw_networkx_edges(G, pos, style=style_seq)
359
+ assert len(drawn_edges) == 3
360
+ for fap, style in zip(drawn_edges, itertools.cycle(style_seq)):
361
+ assert fap.get_linestyle() == style
362
+
363
+
364
+ def test_labels_and_colors():
365
+ G = nx.cubical_graph()
366
+ pos = nx.spring_layout(G) # positions for all nodes
367
+ # nodes
368
+ nx.draw_networkx_nodes(
369
+ G, pos, nodelist=[0, 1, 2, 3], node_color="r", node_size=500, alpha=0.75
370
+ )
371
+ nx.draw_networkx_nodes(
372
+ G,
373
+ pos,
374
+ nodelist=[4, 5, 6, 7],
375
+ node_color="b",
376
+ node_size=500,
377
+ alpha=[0.25, 0.5, 0.75, 1.0],
378
+ )
379
+ # edges
380
+ nx.draw_networkx_edges(G, pos, width=1.0, alpha=0.5)
381
+ nx.draw_networkx_edges(
382
+ G,
383
+ pos,
384
+ edgelist=[(0, 1), (1, 2), (2, 3), (3, 0)],
385
+ width=8,
386
+ alpha=0.5,
387
+ edge_color="r",
388
+ )
389
+ nx.draw_networkx_edges(
390
+ G,
391
+ pos,
392
+ edgelist=[(4, 5), (5, 6), (6, 7), (7, 4)],
393
+ width=8,
394
+ alpha=0.5,
395
+ edge_color="b",
396
+ )
397
+ nx.draw_networkx_edges(
398
+ G,
399
+ pos,
400
+ edgelist=[(4, 5), (5, 6), (6, 7), (7, 4)],
401
+ arrows=True,
402
+ min_source_margin=0.5,
403
+ min_target_margin=0.75,
404
+ width=8,
405
+ edge_color="b",
406
+ )
407
+ # some math labels
408
+ labels = {}
409
+ labels[0] = r"$a$"
410
+ labels[1] = r"$b$"
411
+ labels[2] = r"$c$"
412
+ labels[3] = r"$d$"
413
+ labels[4] = r"$\alpha$"
414
+ labels[5] = r"$\beta$"
415
+ labels[6] = r"$\gamma$"
416
+ labels[7] = r"$\delta$"
417
+ nx.draw_networkx_labels(G, pos, labels, font_size=16)
418
+ nx.draw_networkx_edge_labels(G, pos, edge_labels=None, rotate=False)
419
+ nx.draw_networkx_edge_labels(G, pos, edge_labels={(4, 5): "4-5"})
420
+ # plt.show()
421
+
422
+
423
+ @pytest.mark.mpl_image_compare
424
+ def test_house_with_colors():
425
+ G = nx.house_graph()
426
+ # explicitly set positions
427
+ fig, ax = plt.subplots()
428
+ pos = {0: (0, 0), 1: (1, 0), 2: (0, 1), 3: (1, 1), 4: (0.5, 2.0)}
429
+
430
+ # Plot nodes with different properties for the "wall" and "roof" nodes
431
+ nx.draw_networkx_nodes(
432
+ G,
433
+ pos,
434
+ node_size=3000,
435
+ nodelist=[0, 1, 2, 3],
436
+ node_color="tab:blue",
437
+ )
438
+ nx.draw_networkx_nodes(
439
+ G, pos, node_size=2000, nodelist=[4], node_color="tab:orange"
440
+ )
441
+ nx.draw_networkx_edges(G, pos, alpha=0.5, width=6)
442
+ # Customize axes
443
+ ax.margins(0.11)
444
+ plt.tight_layout()
445
+ plt.axis("off")
446
+ return fig
447
+
448
+
449
+ def test_axes():
450
+ fig, ax = plt.subplots()
451
+ nx.draw(barbell, ax=ax)
452
+ nx.draw_networkx_edge_labels(barbell, nx.circular_layout(barbell), ax=ax)
453
+
454
+
455
+ def test_empty_graph():
456
+ G = nx.Graph()
457
+ nx.draw(G)
458
+
459
+
460
+ def test_draw_empty_nodes_return_values():
461
+ # See Issue #3833
462
+ import matplotlib.collections # call as mpl.collections
463
+
464
+ G = nx.Graph([(1, 2), (2, 3)])
465
+ DG = nx.DiGraph([(1, 2), (2, 3)])
466
+ pos = nx.circular_layout(G)
467
+ assert isinstance(
468
+ nx.draw_networkx_nodes(G, pos, nodelist=[]), mpl.collections.PathCollection
469
+ )
470
+ assert isinstance(
471
+ nx.draw_networkx_nodes(DG, pos, nodelist=[]), mpl.collections.PathCollection
472
+ )
473
+
474
+ # drawing empty edges used to return an empty LineCollection or empty list.
475
+ # Now it is always an empty list (because edges are now lists of FancyArrows)
476
+ assert nx.draw_networkx_edges(G, pos, edgelist=[], arrows=True) == []
477
+ assert nx.draw_networkx_edges(G, pos, edgelist=[], arrows=False) == []
478
+ assert nx.draw_networkx_edges(DG, pos, edgelist=[], arrows=False) == []
479
+ assert nx.draw_networkx_edges(DG, pos, edgelist=[], arrows=True) == []
480
+
481
+
482
+ def test_multigraph_edgelist_tuples():
483
+ # See Issue #3295
484
+ G = nx.path_graph(3, create_using=nx.MultiDiGraph)
485
+ nx.draw_networkx(G, edgelist=[(0, 1, 0)])
486
+ nx.draw_networkx(G, edgelist=[(0, 1, 0)], node_size=[10, 20, 0])
487
+
488
+
489
+ def test_alpha_iter():
490
+ pos = nx.random_layout(barbell)
491
+ fig = plt.figure()
492
+ # with fewer alpha elements than nodes
493
+ fig.add_subplot(131) # Each test in a new axis object
494
+ nx.draw_networkx_nodes(barbell, pos, alpha=[0.1, 0.2])
495
+ # with equal alpha elements and nodes
496
+ num_nodes = len(barbell.nodes)
497
+ alpha = [x / num_nodes for x in range(num_nodes)]
498
+ colors = range(num_nodes)
499
+ fig.add_subplot(132)
500
+ nx.draw_networkx_nodes(barbell, pos, node_color=colors, alpha=alpha)
501
+ # with more alpha elements than nodes
502
+ alpha.append(1)
503
+ fig.add_subplot(133)
504
+ nx.draw_networkx_nodes(barbell, pos, alpha=alpha)
505
+
506
+
507
+ def test_error_invalid_kwds():
508
+ with pytest.raises(ValueError, match="Received invalid argument"):
509
+ nx.draw(barbell, foo="bar")
510
+
511
+
512
+ def test_draw_networkx_arrowsize_incorrect_size():
513
+ G = nx.DiGraph([(0, 1), (0, 2), (0, 3), (1, 3)])
514
+ arrowsize = [1, 2, 3]
515
+ with pytest.raises(
516
+ ValueError, match="arrowsize should have the same length as edgelist"
517
+ ):
518
+ nx.draw(G, arrowsize=arrowsize)
519
+
520
+
521
+ @pytest.mark.parametrize("arrowsize", (30, [10, 20, 30]))
522
+ def test_draw_edges_arrowsize(arrowsize):
523
+ G = nx.DiGraph([(0, 1), (0, 2), (1, 2)])
524
+ pos = {0: (0, 0), 1: (0, 1), 2: (1, 0)}
525
+ edges = nx.draw_networkx_edges(G, pos=pos, arrowsize=arrowsize)
526
+
527
+ arrowsize = itertools.repeat(arrowsize) if isinstance(arrowsize, int) else arrowsize
528
+
529
+ for fap, expected in zip(edges, arrowsize):
530
+ assert isinstance(fap, mpl.patches.FancyArrowPatch)
531
+ assert fap.get_mutation_scale() == expected
532
+
533
+
534
+ def test_np_edgelist():
535
+ # see issue #4129
536
+ nx.draw_networkx(barbell, edgelist=np.array([(0, 2), (0, 3)]))
537
+
538
+
539
+ def test_draw_nodes_missing_node_from_position():
540
+ G = nx.path_graph(3)
541
+ pos = {0: (0, 0), 1: (1, 1)} # No position for node 2
542
+ with pytest.raises(nx.NetworkXError, match="has no position"):
543
+ nx.draw_networkx_nodes(G, pos)
544
+
545
+
546
+ # NOTE: parametrizing on marker to test both branches of internal
547
+ # nx.draw_networkx_edges.to_marker_edge function
548
+ @pytest.mark.parametrize("node_shape", ("o", "s"))
549
+ def test_draw_edges_min_source_target_margins(node_shape):
550
+ """Test that there is a wider gap between the node and the start of an
551
+ incident edge when min_source_margin is specified.
552
+
553
+ This test checks that the use of min_{source/target}_margin kwargs result
554
+ in shorter (more padding) between the edges and source and target nodes.
555
+ As a crude visual example, let 's' and 't' represent source and target
556
+ nodes, respectively:
557
+
558
+ Default:
559
+ s-----------------------------t
560
+
561
+ With margins:
562
+ s ----------------------- t
563
+
564
+ """
565
+ # Create a single axis object to get consistent pixel coords across
566
+ # multiple draws
567
+ fig, ax = plt.subplots()
568
+ G = nx.DiGraph([(0, 1)])
569
+ pos = {0: (0, 0), 1: (1, 0)} # horizontal layout
570
+ # Get leftmost and rightmost points of the FancyArrowPatch object
571
+ # representing the edge between nodes 0 and 1 (in pixel coordinates)
572
+ default_patch = nx.draw_networkx_edges(G, pos, ax=ax, node_shape=node_shape)[0]
573
+ default_extent = default_patch.get_extents().corners()[::2, 0]
574
+ # Now, do the same but with "padding" for the source and target via the
575
+ # min_{source/target}_margin kwargs
576
+ padded_patch = nx.draw_networkx_edges(
577
+ G,
578
+ pos,
579
+ ax=ax,
580
+ node_shape=node_shape,
581
+ min_source_margin=100,
582
+ min_target_margin=100,
583
+ )[0]
584
+ padded_extent = padded_patch.get_extents().corners()[::2, 0]
585
+
586
+ # With padding, the left-most extent of the edge should be further to the
587
+ # right
588
+ assert padded_extent[0] > default_extent[0]
589
+ # And the rightmost extent of the edge, further to the left
590
+ assert padded_extent[1] < default_extent[1]
591
+
592
+
593
+ def test_nonzero_selfloop_with_single_node():
594
+ """Ensure that selfloop extent is non-zero when there is only one node."""
595
+ # Create explicit axis object for test
596
+ fig, ax = plt.subplots()
597
+ # Graph with single node + self loop
598
+ G = nx.DiGraph()
599
+ G.add_node(0)
600
+ G.add_edge(0, 0)
601
+ # Draw
602
+ patch = nx.draw_networkx_edges(G, {0: (0, 0)})[0]
603
+ # The resulting patch must have non-zero extent
604
+ bbox = patch.get_extents()
605
+ assert bbox.width > 0 and bbox.height > 0
606
+ # Cleanup
607
+ plt.delaxes(ax)
608
+ plt.close()
609
+
610
+
611
+ def test_nonzero_selfloop_with_single_edge_in_edgelist():
612
+ """Ensure that selfloop extent is non-zero when only a single edge is
613
+ specified in the edgelist.
614
+ """
615
+ # Create explicit axis object for test
616
+ fig, ax = plt.subplots()
617
+ # Graph with selfloop
618
+ G = nx.path_graph(2, create_using=nx.DiGraph)
619
+ G.add_edge(1, 1)
620
+ pos = {n: (n, n) for n in G.nodes}
621
+ # Draw only the selfloop edge via the `edgelist` kwarg
622
+ patch = nx.draw_networkx_edges(G, pos, edgelist=[(1, 1)])[0]
623
+ # The resulting patch must have non-zero extent
624
+ bbox = patch.get_extents()
625
+ assert bbox.width > 0 and bbox.height > 0
626
+ # Cleanup
627
+ plt.delaxes(ax)
628
+ plt.close()
629
+
630
+
631
+ def test_apply_alpha():
632
+ """Test apply_alpha when there is a mismatch between the number of
633
+ supplied colors and elements.
634
+ """
635
+ nodelist = [0, 1, 2]
636
+ colorlist = ["r", "g", "b"]
637
+ alpha = 0.5
638
+ rgba_colors = nx.drawing.nx_pylab.apply_alpha(colorlist, alpha, nodelist)
639
+ assert all(rgba_colors[:, -1] == alpha)
640
+
641
+
642
+ def test_draw_edges_toggling_with_arrows_kwarg():
643
+ """
644
+ The `arrows` keyword argument is used as a 3-way switch to select which
645
+ type of object to use for drawing edges:
646
+ - ``arrows=None`` -> default (FancyArrowPatches for directed, else LineCollection)
647
+ - ``arrows=True`` -> FancyArrowPatches
648
+ - ``arrows=False`` -> LineCollection
649
+ """
650
+ import matplotlib.collections
651
+ import matplotlib.patches
652
+
653
+ UG = nx.path_graph(3)
654
+ DG = nx.path_graph(3, create_using=nx.DiGraph)
655
+ pos = {n: (n, n) for n in UG}
656
+
657
+ # Use FancyArrowPatches when arrows=True, regardless of graph type
658
+ for G in (UG, DG):
659
+ edges = nx.draw_networkx_edges(G, pos, arrows=True)
660
+ assert len(edges) == len(G.edges)
661
+ assert isinstance(edges[0], mpl.patches.FancyArrowPatch)
662
+
663
+ # Use LineCollection when arrows=False, regardless of graph type
664
+ for G in (UG, DG):
665
+ edges = nx.draw_networkx_edges(G, pos, arrows=False)
666
+ assert isinstance(edges, mpl.collections.LineCollection)
667
+
668
+ # Default behavior when arrows=None: FAPs for directed, LC's for undirected
669
+ edges = nx.draw_networkx_edges(UG, pos)
670
+ assert isinstance(edges, mpl.collections.LineCollection)
671
+ edges = nx.draw_networkx_edges(DG, pos)
672
+ assert len(edges) == len(G.edges)
673
+ assert isinstance(edges[0], mpl.patches.FancyArrowPatch)
674
+
675
+
676
+ @pytest.mark.parametrize("drawing_func", (nx.draw, nx.draw_networkx))
677
+ def test_draw_networkx_arrows_default_undirected(drawing_func):
678
+ import matplotlib.collections
679
+
680
+ G = nx.path_graph(3)
681
+ fig, ax = plt.subplots()
682
+ drawing_func(G, ax=ax)
683
+ assert any(isinstance(c, mpl.collections.LineCollection) for c in ax.collections)
684
+ assert not ax.patches
685
+ plt.delaxes(ax)
686
+ plt.close()
687
+
688
+
689
+ @pytest.mark.parametrize("drawing_func", (nx.draw, nx.draw_networkx))
690
+ def test_draw_networkx_arrows_default_directed(drawing_func):
691
+ import matplotlib.collections
692
+
693
+ G = nx.path_graph(3, create_using=nx.DiGraph)
694
+ fig, ax = plt.subplots()
695
+ drawing_func(G, ax=ax)
696
+ assert not any(
697
+ isinstance(c, mpl.collections.LineCollection) for c in ax.collections
698
+ )
699
+ assert ax.patches
700
+ plt.delaxes(ax)
701
+ plt.close()
702
+
703
+
704
+ def test_edgelist_kwarg_not_ignored():
705
+ # See gh-4994
706
+ G = nx.path_graph(3)
707
+ G.add_edge(0, 0)
708
+ fig, ax = plt.subplots()
709
+ nx.draw(G, edgelist=[(0, 1), (1, 2)], ax=ax) # Exclude self-loop from edgelist
710
+ assert not ax.patches
711
+ plt.delaxes(ax)
712
+ plt.close()
713
+
714
+
715
+ @pytest.mark.parametrize(
716
+ ("G", "expected_n_edges"),
717
+ ([nx.DiGraph(), 2], [nx.MultiGraph(), 4], [nx.MultiDiGraph(), 4]),
718
+ )
719
+ def test_draw_networkx_edges_multiedge_connectionstyle(G, expected_n_edges):
720
+ """Draws edges correctly for 3 types of graphs and checks for valid length"""
721
+ for i, (u, v) in enumerate([(0, 1), (0, 1), (0, 1), (0, 2)]):
722
+ G.add_edge(u, v, weight=round(i / 3, 2))
723
+ pos = {n: (n, n) for n in G}
724
+ # Raises on insuficient connectionstyle length
725
+ for conn_style in [
726
+ "arc3,rad=0.1",
727
+ ["arc3,rad=0.1", "arc3,rad=0.1"],
728
+ ["arc3,rad=0.1", "arc3,rad=0.1", "arc3,rad=0.2"],
729
+ ]:
730
+ nx.draw_networkx_edges(G, pos, connectionstyle=conn_style)
731
+ arrows = nx.draw_networkx_edges(G, pos, connectionstyle=conn_style)
732
+ assert len(arrows) == expected_n_edges
733
+
734
+
735
+ @pytest.mark.parametrize(
736
+ ("G", "expected_n_edges"),
737
+ ([nx.DiGraph(), 2], [nx.MultiGraph(), 4], [nx.MultiDiGraph(), 4]),
738
+ )
739
+ def test_draw_networkx_edge_labels_multiedge_connectionstyle(G, expected_n_edges):
740
+ """Draws labels correctly for 3 types of graphs and checks for valid length and class names"""
741
+ for i, (u, v) in enumerate([(0, 1), (0, 1), (0, 1), (0, 2)]):
742
+ G.add_edge(u, v, weight=round(i / 3, 2))
743
+ pos = {n: (n, n) for n in G}
744
+ # Raises on insuficient connectionstyle length
745
+ arrows = nx.draw_networkx_edges(
746
+ G, pos, connectionstyle=["arc3,rad=0.1", "arc3,rad=0.1", "arc3,rad=0.1"]
747
+ )
748
+ for conn_style in [
749
+ "arc3,rad=0.1",
750
+ ["arc3,rad=0.1", "arc3,rad=0.2"],
751
+ ["arc3,rad=0.1", "arc3,rad=0.1", "arc3,rad=0.1"],
752
+ ]:
753
+ text_items = nx.draw_networkx_edge_labels(G, pos, connectionstyle=conn_style)
754
+ assert len(text_items) == expected_n_edges
755
+ for ti in text_items.values():
756
+ assert ti.__class__.__name__ == "CurvedArrowText"
757
+
758
+
759
+ def test_draw_networkx_edge_label_multiedge():
760
+ G = nx.MultiGraph()
761
+ G.add_edge(0, 1, weight=10)
762
+ G.add_edge(0, 1, weight=20)
763
+ edge_labels = nx.get_edge_attributes(G, "weight") # Includes edge keys
764
+ pos = {n: (n, n) for n in G}
765
+ text_items = nx.draw_networkx_edge_labels(
766
+ G,
767
+ pos,
768
+ edge_labels=edge_labels,
769
+ connectionstyle=["arc3,rad=0.1", "arc3,rad=0.2"],
770
+ )
771
+ assert len(text_items) == 2
772
+
773
+
774
+ def test_draw_networkx_edge_label_empty_dict():
775
+ """Regression test for draw_networkx_edge_labels with empty dict. See
776
+ gh-5372."""
777
+ G = nx.path_graph(3)
778
+ pos = {n: (n, n) for n in G.nodes}
779
+ assert nx.draw_networkx_edge_labels(G, pos, edge_labels={}) == {}
780
+
781
+
782
+ def test_draw_networkx_edges_undirected_selfloop_colors():
783
+ """When an edgelist is supplied along with a sequence of colors, check that
784
+ the self-loops have the correct colors."""
785
+ fig, ax = plt.subplots()
786
+ # Edge list and corresponding colors
787
+ edgelist = [(1, 3), (1, 2), (2, 3), (1, 1), (3, 3), (2, 2)]
788
+ edge_colors = ["pink", "cyan", "black", "red", "blue", "green"]
789
+
790
+ G = nx.Graph(edgelist)
791
+ pos = {n: (n, n) for n in G.nodes}
792
+ nx.draw_networkx_edges(G, pos, ax=ax, edgelist=edgelist, edge_color=edge_colors)
793
+
794
+ # Verify that there are three fancy arrow patches (1 per self loop)
795
+ assert len(ax.patches) == 3
796
+
797
+ # These are points that should be contained in the self loops. For example,
798
+ # sl_points[0] will be (1, 1.1), which is inside the "path" of the first
799
+ # self-loop but outside the others
800
+ sl_points = np.array(edgelist[-3:]) + np.array([0, 0.1])
801
+
802
+ # Check that the mapping between self-loop locations and their colors is
803
+ # correct
804
+ for fap, clr, slp in zip(ax.patches, edge_colors[-3:], sl_points):
805
+ assert fap.get_path().contains_point(slp)
806
+ assert mpl.colors.same_color(fap.get_edgecolor(), clr)
807
+ plt.delaxes(ax)
808
+ plt.close()
809
+
810
+
811
+ @pytest.mark.parametrize(
812
+ "fap_only_kwarg", # Non-default values for kwargs that only apply to FAPs
813
+ (
814
+ {"arrowstyle": "-"},
815
+ {"arrowsize": 20},
816
+ {"connectionstyle": "arc3,rad=0.2"},
817
+ {"min_source_margin": 10},
818
+ {"min_target_margin": 10},
819
+ ),
820
+ )
821
+ def test_user_warnings_for_unused_edge_drawing_kwargs(fap_only_kwarg):
822
+ """Users should get a warning when they specify a non-default value for
823
+ one of the kwargs that applies only to edges drawn with FancyArrowPatches,
824
+ but FancyArrowPatches aren't being used under the hood."""
825
+ G = nx.path_graph(3)
826
+ pos = {n: (n, n) for n in G}
827
+ fig, ax = plt.subplots()
828
+ # By default, an undirected graph will use LineCollection to represent
829
+ # the edges
830
+ kwarg_name = list(fap_only_kwarg.keys())[0]
831
+ with pytest.warns(
832
+ UserWarning, match=f"\n\nThe {kwarg_name} keyword argument is not applicable"
833
+ ):
834
+ nx.draw_networkx_edges(G, pos, ax=ax, **fap_only_kwarg)
835
+ # FancyArrowPatches are always used when `arrows=True` is specified.
836
+ # Check that warnings are *not* raised in this case
837
+ with warnings.catch_warnings():
838
+ # Escalate warnings -> errors so tests fail if warnings are raised
839
+ warnings.simplefilter("error")
840
+ nx.draw_networkx_edges(G, pos, ax=ax, arrows=True, **fap_only_kwarg)
841
+
842
+ plt.delaxes(ax)
843
+ plt.close()
844
+
845
+
846
+ @pytest.mark.parametrize("draw_fn", (nx.draw, nx.draw_circular))
847
+ def test_no_warning_on_default_draw_arrowstyle(draw_fn):
848
+ # See gh-7284
849
+ fig, ax = plt.subplots()
850
+ G = nx.cycle_graph(5)
851
+ with warnings.catch_warnings(record=True) as w:
852
+ draw_fn(G, ax=ax)
853
+ assert len(w) == 0
854
+
855
+ plt.delaxes(ax)
856
+ plt.close()
857
+
858
+
859
+ @pytest.mark.parametrize("hide_ticks", [False, True])
860
+ @pytest.mark.parametrize(
861
+ "method",
862
+ [
863
+ nx.draw_networkx,
864
+ nx.draw_networkx_edge_labels,
865
+ nx.draw_networkx_edges,
866
+ nx.draw_networkx_labels,
867
+ nx.draw_networkx_nodes,
868
+ ],
869
+ )
870
+ def test_hide_ticks(method, hide_ticks):
871
+ G = nx.path_graph(3)
872
+ pos = {n: (n, n) for n in G.nodes}
873
+ _, ax = plt.subplots()
874
+ method(G, pos=pos, ax=ax, hide_ticks=hide_ticks)
875
+ for axis in [ax.xaxis, ax.yaxis]:
876
+ assert bool(axis.get_ticklabels()) != hide_ticks
877
+
878
+ plt.delaxes(ax)
879
+ plt.close()
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.48 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/atlas.cpython-310.pyc ADDED
Binary file (4.33 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/classic.cpython-310.pyc ADDED
Binary file (29.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/cographs.cpython-310.pyc ADDED
Binary file (2.24 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/community.cpython-310.pyc ADDED
Binary file (31.2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/degree_seq.cpython-310.pyc ADDED
Binary file (25.7 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/directed.cpython-310.pyc ADDED
Binary file (15 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/duplication.cpython-310.pyc ADDED
Binary file (4.41 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/ego.cpython-310.pyc ADDED
Binary file (1.82 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/expanders.cpython-310.pyc ADDED
Binary file (12.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/geometric.cpython-310.pyc ADDED
Binary file (38.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/harary_graph.cpython-310.pyc ADDED
Binary file (4.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/internet_as_graphs.cpython-310.pyc ADDED
Binary file (12.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/intersection.cpython-310.pyc ADDED
Binary file (4.27 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/interval_graph.cpython-310.pyc ADDED
Binary file (2.33 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/joint_degree_seq.cpython-310.pyc ADDED
Binary file (17.2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/lattice.cpython-310.pyc ADDED
Binary file (15 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/line.cpython-310.pyc ADDED
Binary file (15.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/mycielski.cpython-310.pyc ADDED
Binary file (3.86 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/nonisomorphic_trees.cpython-310.pyc ADDED
Binary file (5.65 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/random_clustered.cpython-310.pyc ADDED
Binary file (4.13 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/random_graphs.cpython-310.pyc ADDED
Binary file (35.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/small.cpython-310.pyc ADDED
Binary file (26.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/social.cpython-310.pyc ADDED
Binary file (12.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/spectral_graph_forge.cpython-310.pyc ADDED
Binary file (4.23 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/stochastic.cpython-310.pyc ADDED
Binary file (2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/sudoku.cpython-310.pyc ADDED
Binary file (4.05 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/time_series.cpython-310.pyc ADDED
Binary file (2.6 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/trees.cpython-310.pyc ADDED
Binary file (36.7 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/__pycache__/triads.cpython-310.pyc ADDED
Binary file (2.29 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (190 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_atlas.cpython-310.pyc ADDED
Binary file (3.58 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_classic.cpython-310.pyc ADDED
Binary file (21.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_cographs.cpython-310.pyc ADDED
Binary file (655 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_community.cpython-310.pyc ADDED
Binary file (10.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_degree_seq.cpython-310.pyc ADDED
Binary file (8.64 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_directed.cpython-310.pyc ADDED
Binary file (7.01 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_duplication.cpython-310.pyc ADDED
Binary file (3.57 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_ego.cpython-310.pyc ADDED
Binary file (1.57 kB). View file
 
env-llmeval/lib/python3.10/site-packages/networkx/generators/tests/__pycache__/test_expanders.cpython-310.pyc ADDED
Binary file (5.85 kB). View file