code: def test_connected_components(self, xp, sp):
      a = self._make_matrix(self.dtype, xp)
      a = sp.csr_matrix(a)
      if self.return_labels:
          n, labels = sp.csgraph.connected_components(
              a,
              directed=self.directed,
              connection=self.connection,
              return_labels=self.return_labels,
          )
          # Note: CuPy returns un-ordered results in both strong and
          # weak connection case while SciPy returns un-ordered labels
          # in strong connection case therefore. Since in most cases
          # the labels returned by both cuPy and Scipy are un-ordered
          # therefore, always adjust the labels.
          table = xp.zeros((n,), dtype=numpy.int32) - 1
          j = 0
          for i in range(labels.size):
              if table[labels[i]] < 0:
                  table[labels[i]] = j
                  j = j + 1
              labels[i] = table[labels[i]]
          return n, labels
      else:
          return sp.csgraph.connected_components(
              a,
              directed=self.directed,
              connection=self.connection,
              return_labels=self.return_labels,
          )
  
imports: import unittest
  import numpy
  import cupyx.scipy.sparse.csgraph
  from cupy import testing
label_desc: Use image node_id 2 for calling the TestConnectedComponents obj's underlying member method code with example usage: obj.test_connected_components(xp, sp) and returns: n,  labels, sp