code: def testGraphNetworkx(self):
      # Undirected
      g = Graph.Ring(10)
      g["gattr"] = "graph_attribute"
      g.vs["vattr"] = list(range(g.vcount()))
      g.es["eattr"] = list(range(len(g.es)))
  
      # Go to networkx and back
      g_nx = g.to_networkx()
      g2 = Graph.from_networkx(g_nx)
  
      self.assertFalse(g2.is_directed())
      self.assertTrue(g2.is_simple())
      self.assertEqual(g.vcount(), g2.vcount())
      self.assertEqual(
          sorted(g.get_edgelist()), sorted(g2.get_edgelist())
      )
  
      # Test attributes
      self.assertEqual(g.attributes(), g2.attributes())
      self.assertEqual(
          sorted(["vattr", "_nx_name"]), sorted(g2.vertex_attributes())
      )
      for i, vertex in enumerate(g.vs):
          vertex2 = g2.vs[i]
          for an in vertex.attribute_names():
              if an == "vattr":
                  continue
              self.assertEqual(
                  vertex.attributes()[an], vertex2.attributes()[an]
              )
      self.assertEqual(g.edge_attributes(), g2.edge_attributes())
      for edge in g.es:
          eid = g2.get_eid(edge.source, edge.target)
          edge2 = g2.es[eid]
          for an in edge.attribute_names():
              self.assertEqual(
                  edge.attributes()[an], edge2.attributes()[an]
              )
  
      # Directed
      g = Graph.Ring(10, directed=True)
  
      # Go to networkx and back
      g_nx = g.to_networkx()
      g2 = Graph.from_networkx(g_nx)
  
      self.assertTrue(g2.is_directed())
      self.assertTrue(g2.is_simple())
      self.assertEqual(g.vcount(), g2.vcount())
      self.assertEqual(
          sorted(g.get_edgelist()), sorted(g2.get_edgelist())
      )
  
      # Test networkx with custom node hashables
      # In this case each node is a tuple of ints
      g_nx = nx.DiGraph()
      inf = float("inf")
      g_nx.add_edges_from(
          (
              ((0, 0), (1, 1), {"weight": 3.0}),
              ((0, 0), (1, 0), {"weight": inf}),
          )
      )
      g = Graph.from_networkx(g_nx)
      self.assertTrue(g.is_directed())
      self.assertEqual(g.vcount(), 3)
      self.assertTrue(
          g.es["weight"] == [3.0, inf] or g.es["weight"] == [inf, 3.0]
      )
  
imports: import gzip
  import io
  import unittest
  import warnings
  from igraph import Graph, InternalError
  from .utils import temporary_file
label_desc: Use image node_id 18 for calling the ForeignTests obj's underlying member method code with example usage: obj.testGraphNetworkx() without return types