code: def testCartcomm(self):
      comm = self.COMM
      size = comm.Get_size()
      rank = comm.Get_rank()
      for ndim in (1, 2, 3, 4, 5):
          dims = MPI.Compute_dims(size, [0] * ndim)
          periods = [True] * len(dims)
          topo = comm.Create_cart(dims, periods=periods)
          self.assertTrue(topo.is_topo)
          self.assertEqual(topo.topology, MPI.CART)
          self.checkFortran(topo)
          self.assertEqual(topo.dim, len(dims))
          self.assertEqual(topo.ndim, len(dims))
          coords = topo.coords
          self.assertEqual(coords, topo.Get_coords(topo.rank))
          self.assertEqual(topo.topo, (dims, periods, coords))
          neighbors = []
          coordinates = topo.Get_coords(topo.rank)
          for i in range(ndim):
              for d in (-1, +1):
                  coord = list(coordinates)
                  coord[i] = (coord[i] + d) % dims[i]
                  neigh = topo.Get_cart_rank(coord)
                  self.assertEqual(coord, topo.Get_coords(neigh))
                  source, dest = topo.Shift(i, d)
                  self.assertEqual(neigh, dest)
                  neighbors.append(neigh)
          self.assertEqual(topo.indegree, len(neighbors))
          self.assertEqual(topo.outdegree, len(neighbors))
          self.assertEqual(topo.inedges, neighbors)
          self.assertEqual(topo.outedges, neighbors)
          inedges, outedges = topo.inoutedges
          self.assertEqual(inedges, neighbors)
          self.assertEqual(outedges, neighbors)
          if ndim == 1:
              topo.Free()
              continue
          for i in range(ndim):
              rem_dims = [1] * ndim
              rem_dims[i] = 0
              sub = topo.Sub(rem_dims)
              if sub != MPI.COMM_NULL:
                  self.assertEqual(sub.dim, ndim - 1)
                  dims = topo.dims
                  del dims[i]
                  self.assertEqual(sub.dims, dims)
                  sub.Free()
          topo.Free()
      with self.assertRaises(ValueError):
          topo = comm.Create_cart([comm.Get_size()], [])
      with self.assertRaises(ValueError):
          topo = comm.Create_cart([comm.Get_size()], [0, 0])
  
imports: from mpi4py import MPI
  import mpiunittest
label_desc: Use image node_id 2 for calling the BaseTestTopo obj's underlying member method code with example usage: obj.testCartcomm() without return types