code: def testToUndirected(self):
      graph = Graph([(0, 1), (0, 2), (1, 0)], directed=True)
  
      graph2 = graph.copy()
      graph2.to_undirected(mode=False)
      self.assertTrue(graph2.vcount() == graph.vcount())
      self.assertTrue(graph2.is_directed() is False)
      self.assertTrue(
          sorted(graph2.get_edgelist()) == [(0, 1), (0, 1), (0, 2)]
      )
  
      graph2 = graph.copy()
      graph2.to_undirected()
      self.assertTrue(graph2.vcount() == graph.vcount())
      self.assertTrue(graph2.is_directed() is False)
      self.assertTrue(sorted(graph2.get_edgelist()) == [(0, 1), (0, 2)])
  
      graph2 = graph.copy()
      graph2.es["weight"] = [1, 2, 3]
      graph2.to_undirected(mode="collapse", combine_edges="sum")
      self.assertTrue(graph2.vcount() == graph.vcount())
      self.assertTrue(graph2.is_directed() is False)
      self.assertTrue(sorted(graph2.get_edgelist()) == [(0, 1), (0, 2)])
      self.assertTrue(graph2.es["weight"] == [4, 2])
  
      graph = Graph(
          [(0, 1), (1, 0), (0, 1), (1, 0), (2, 1), (1, 2)],
          directed=True,
      )
      graph2 = graph.copy()
      graph2.es["weight"] = [1, 2, 3, 4, 5, 6]
      graph2.to_undirected(mode="mutual", combine_edges="sum")
      self.assertTrue(graph2.vcount() == graph.vcount())
      self.assertTrue(graph2.is_directed() is False)
      self.assertTrue(
          sorted(graph2.get_edgelist()) == [(0, 1), (0, 1), (1, 2)]
      )
      self.assertTrue(
          graph2.es["weight"] == [7, 3, 11]
          or graph2.es["weight"] == [3, 7, 11]
      )
  
file_path: python-igraph/tests/test_conversion.py
imports: import random
  import unittest
  from igraph import Graph, Matrix
label_desc: Use image node_id 1 for calling the DirectedUndirectedTests obj's underlying member method code with example usage: obj.testToUndirected() without return types