def test_order_preserving(self):
    """Tests that edges order can be preserved when importing from networks."""
    graph = nx.DiGraph()
    for node_index in range(4):
      graph.add_node(node_index, features=np.array([node_index]))
    receivers = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
    senders = [1, 2, 3, 0, 2, 3, 0, 1, 3, 0, 1, 2]
    for edge_index, (receiver, sender) in enumerate(zip(receivers, senders)):
      # Removing the "index" key makes this test fail 100%.
      edge_data = {"features": np.array([edge_index]), "index": edge_index}
      graph.add_edge(sender, receiver, **edge_data)
    graph.graph["features"] = np.array([0.])
    graphs_graph = utils_np.networkx_to_data_dict(graph)
    self.assertAllEqual(receivers, graphs_graph["receivers"])
    self.assertAllEqual(senders, graphs_graph["senders"])
    self.assertAllEqual([[x] for x in range(4)], graphs_graph["nodes"])
    self.assertAllEqual([[x] for x in range(12)], graphs_graph["edges"])
Tests that edges order can be preserved when importing from networks.
graph_nets/tests/utils_np_test.py