code: def test_nifti_labels_masker_report(data_img_3d, mask, affine_eye):
      shape = (13, 11, 12)
      n_regions = 9
      labels = ["background"] + [
          f"region_{i}" for i in range(1, n_regions + 1)
      ]
      EXPECTED_COLUMNS = [
          "label value",
          "region name",
          "size (in mm^3)",
          "relative size (in %)",
      ]
      labels_img = generate_labeled_regions(
          shape, affine=affine_eye, n_regions=n_regions
      )
      labels_img_floats = new_img_like(
          labels_img, get_data(labels_img).astype(float)
      )
      masker = NiftiLabelsMasker(labels_img_floats, labels=labels)
      masker.fit()
      masker.generate_report()
  
      # Check that providing incorrect labels raises an error
      masker = NiftiLabelsMasker(labels_img, labels=labels[:-1])
      masker.fit()
      with pytest.raises(
          ValueError,
          match="Mismatch between the number of provided labels",
      ):
          masker.generate_report()
      masker = NiftiLabelsMasker(labels_img, labels=labels)
      masker.fit()
      # Check that a warning is given when generating the report
      # since no image was provided to fit
      with pytest.warns(
          UserWarning,
          match="No image provided to fit in NiftiLabelsMasker",
      ):
          masker.generate_report()
  
      # No image was provided to fit, regions are plotted using
      # plot_roi such that no contour should be in the image
      display = masker._reporting()
      for d in ["x", "y", "z"]:
          assert len(display[0].axes[d].ax.collections) == 0
  
      masker = NiftiLabelsMasker(labels_img, labels=labels)
      masker.fit(data_img_3d)
  
      display = masker._reporting()
      for d in ["x", "y", "z"]:
          assert len(display[0].axes[d].ax.collections) > 0
          assert len(display[0].axes[d].ax.collections) <= n_regions
  
      masker = NiftiLabelsMasker(
          labels_img, labels=labels, mask_img=mask
      )
      masker.fit(data_img_3d)
      report = masker.generate_report()
      assert masker._reporting_data is not None
      # Check that background label was left as default
      assert masker.background_label == 0
      assert masker._report_content["description"] == (
          "This reports shows the regions defined by the labels of the mask."
      )
      # Check that the number of regions is correct
      assert masker._report_content["number_of_regions"] == n_regions
      # Check that all expected columns are present with the right size
      for col in EXPECTED_COLUMNS:
          assert col in masker._report_content["summary"]
          assert (
              len(masker._report_content["summary"][col]) == n_regions
          )
      # Check that labels match
      assert (
          masker._report_content["summary"]["region name"] == labels[1:]
      )
      # Relative sizes of regions should sum to 100%
      assert_almost_equal(
          sum(
              masker._report_content["summary"]["relative size (in %)"]
          ),
          100,
      )
      _check_html(report)
      assert "Regions summary" in str(report)
      # Check region sizes calculations
      expected_region_sizes = Counter(get_data(labels_img).ravel())
      for r in range(1, n_regions + 1):
          assert_almost_equal(
              masker._report_content["summary"]["size (in mm^3)"][
                  r - 1
              ],
              expected_region_sizes[r]
              * np.abs(np.linalg.det(affine_eye[:3, :3])),
          )
  
      # Check that region labels are no displayed in the report
      # when they were not provided by the user.
      masker = NiftiLabelsMasker(labels_img)
      masker.fit()
      report = masker.generate_report()
      for col in EXPECTED_COLUMNS:
          if col == "region name":
              assert col not in masker._report_content["summary"]
          else:
              assert col in masker._report_content["summary"]
              assert (
                  len(masker._report_content["summary"][col])
                  == n_regions
              )
  
imports: from collections import Counter
  import numpy
  import pytest
  from nibabel import Nifti1Image
  from numpy.testing import assert_almost_equal
  from nilearn._utils.data_gen import generate_fake_fmri, generate_labeled_regions, generate_maps, generate_random_img
  from nilearn.image import get_data, new_img_like
  from nilearn.maskers import MultiNiftiLabelsMasker, MultiNiftiMapsMasker, MultiNiftiMasker, NiftiLabelsMasker, NiftiMapsMasker, NiftiMasker, NiftiSpheresMasker
label_desc: Use image node_id 20 for calling a global function with example usage: test_nifti_labels_masker_report(data_img_3d, mask, affine_eye) without return types