code: def test_to_networkx_undirected():
      import networkx as nx
  
      x = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
      pos = torch.tensor([[0.0, 0.0], [1.0, 1.0]])
      edge_index = torch.tensor([[0, 1, 0], [1, 0, 0]])
      edge_attr = torch.tensor([1.0, 2.0, 3.0])
      data = Data(x=x, pos=pos, edge_index=edge_index, weight=edge_attr)
  
      for remove_self_loops in [True, False]:
          G = to_networkx(
              data,
              node_attrs=["x", "pos"],
              edge_attrs=["weight"],
              remove_self_loops=remove_self_loops,
              to_undirected=True,
          )
  
          assert G.nodes[0]["x"] == [1, 2]
          assert G.nodes[1]["x"] == [3, 4]
          assert G.nodes[0]["pos"] == [0, 0]
          assert G.nodes[1]["pos"] == [1, 1]
  
          if remove_self_loops:
              assert nx.to_numpy_array(G).tolist() == [[0, 2], [2, 0]]
          else:
              assert nx.to_numpy_array(G).tolist() == [[3, 2], [2, 0]]
  
      G = to_networkx(data, edge_attrs=["weight"], to_undirected=False)
      assert nx.to_numpy_array(G).tolist() == [[3, 1], [2, 0]]
  
      G = to_networkx(
          data, edge_attrs=["weight"], to_undirected="upper"
      )
      assert nx.to_numpy_array(G).tolist() == [[3, 1], [1, 0]]
  
      G = to_networkx(
          data, edge_attrs=["weight"], to_undirected="lower"
      )
      assert nx.to_numpy_array(G).tolist() == [[3, 2], [2, 0]]
  
imports: import pytest
  import scipy.sparse
  import torch
  from torch_geometric.data import Data, HeteroData
  from torch_geometric.testing import get_random_edge_index, withPackage
  from torch_geometric.utils import from_cugraph, from_dgl, from_networkit, from_networkx, from_scipy_sparse_matrix, from_trimesh, sort_edge_index, subgraph, to_cugraph, to_dgl, to_networkit, to_networkx, to_scipy_sparse_matrix, to_trimesh
label_desc: Use image node_id 5 for calling a global function with example usage: test_to_networkx_undirected() without return types