MCPcopy
hub / github.com/networkx/networkx / test_graph

Method test_graph

networkx/tests/test_convert.py:102–132  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

100 assert sorted(G.edges()) == sorted(GI.edges())
101
102 def test_graph(self):
103 g = nx.cycle_graph(10)
104 G = nx.Graph()
105 G.add_nodes_from(g)
106 G.add_weighted_edges_from((u, v, u) for u, v in g.edges())
107
108 # Dict of dicts
109 dod = to_dict_of_dicts(G)
110 GG = from_dict_of_dicts(dod, create_using=nx.Graph)
111 assert nodes_equal(sorted(G.nodes()), sorted(GG.nodes()))
112 assert edges_equal(sorted(G.edges()), sorted(GG.edges()))
113 GW = to_networkx_graph(dod, create_using=nx.Graph)
114 assert nodes_equal(sorted(G.nodes()), sorted(GW.nodes()))
115 assert edges_equal(sorted(G.edges()), sorted(GW.edges()))
116 GI = nx.Graph(dod)
117 assert sorted(G.nodes()) == sorted(GI.nodes())
118 assert sorted(G.edges()) == sorted(GI.edges())
119
120 # Dict of lists
121 dol = to_dict_of_lists(G)
122 GG = from_dict_of_lists(dol, create_using=nx.Graph)
123 # dict of lists throws away edge data so set it to none
124 enone = [(u, v, {}) for (u, v, d) in G.edges(data=True)]
125 assert nodes_equal(sorted(G.nodes()), sorted(GG.nodes()))
126 assert edges_equal(enone, sorted(GG.edges(data=True)))
127 GW = to_networkx_graph(dol, create_using=nx.Graph)
128 assert nodes_equal(sorted(G.nodes()), sorted(GW.nodes()))
129 assert edges_equal(enone, sorted(GW.edges(data=True)))
130 GI = nx.Graph(dol)
131 assert nodes_equal(sorted(G.nodes()), sorted(GI.nodes()))
132 assert edges_equal(enone, sorted(GI.edges(data=True)))
133
134 def test_with_multiedges_self_loops(self):
135 G = cycle_graph(10)

Callers

nothing calls this directly

Calls 11

add_nodes_fromMethod · 0.95
edgesMethod · 0.95
nodesMethod · 0.95
to_dict_of_dictsFunction · 0.90
from_dict_of_dictsFunction · 0.90
nodes_equalFunction · 0.90
edges_equalFunction · 0.90
to_networkx_graphFunction · 0.90
to_dict_of_listsFunction · 0.90
from_dict_of_listsFunction · 0.90

Tested by

no test coverage detected