code: def testEigenvectorCentrality(self):
      # Temporarily turn off the warning handler because g.evcent() will print
      # a warning for DAGs
      warnings.simplefilter("ignore")
  
      try:
          for idx, g in enumerate(self.__class__.graphs):
              try:
                  ec, eval = g.evcent(return_eigenvalue=True)
              except Exception as ex:
                  self.assertTrue(
                      False,
                      msg="Eigenvector centrality threw exception for graph #%d: %s"
                      % (idx, ex),
                  )
                  raise
  
              if g.vcount() == 0:
                  self.assertEqual([], ec)
                  continue
  
              if not g.is_connected():
                  # Skip disconnected graphs; this will be fixed in igraph 0.7
                  continue
  
              n = g.vcount()
              if abs(eval) < 1e-4:
                  self.assertTrue(
                      min(ec) >= -1e-10,
                      msg="Minimum eigenvector centrality is smaller than 0 for graph #%d"
                      % idx,
                  )
                  self.assertTrue(
                      max(ec) <= 1,
                      msg="Maximum eigenvector centrality is greater than 1 for graph #%d"
                      % idx,
                  )
                  continue
  
              self.assertAlmostEqual(
                  max(ec),
                  1,
                  places=7,
                  msg="Maximum eigenvector centrality is %r (not 1) for graph #%d (%r)"
                  % (max(ec), idx, ec),
              )
              self.assertTrue(
                  min(ec) >= 0,
                  msg="Minimum eigenvector centrality is less than 0 for graph #%d"
                  % idx,
              )
  
              ec2 = [
                  sum(ec[u.index] for u in v.predecessors())
                  for v in g.vs
              ]
              for i in range(n):
                  self.assertAlmostEqual(
                      ec[i] * eval,
                      ec2[i],
                      places=7,
                      msg="Eigenvector centrality in graph #%d seems to be invalid "
                      "for vertex %d" % (idx, i),
                  )
      finally:
          # Reset the warning handler
          warnings.resetwarnings()
  
file_path: python-igraph/tests/test_atlas.py
imports: import warnings
  import unittest
  from igraph import Graph
label_desc: Use image node_id 2 for calling the AtlasTestBase obj's underlying member method code with example usage: obj.testEigenvectorCentrality() without return types