code: def test_non_parametric_inference_cluster_level_with_covariates(
      tmp_path,
      rng,
  ):
      """Test non-parametric inference with cluster-level inference in \
      the context of covariates."""
      shapes = ((7, 8, 9, 1),)
      mask, FUNCFILE, _ = write_fake_fmri_data_and_design(
          shapes, file_path=tmp_path
      )
      func_img = load(FUNCFILE[0])
  
      unc_pval = 0.01
      n_subjects = 2
  
      # Set up one sample t-test design with two random covariates
      cov1 = rng.random(n_subjects)
      cov2 = rng.random(n_subjects)
      X = pd.DataFrame({"cov1": cov1, "cov2": cov2, "intercept": 1})
  
      # make sure there is variability in the images
      kernels = rng.uniform(low=0, high=5, size=n_subjects)
      Y = [smooth_img(func_img, kernel) for kernel in kernels]
  
      # Set up non-parametric test
      out = non_parametric_inference(
          Y,
          design_matrix=X,
          mask=mask,
          model_intercept=False,
          second_level_contrast="intercept",
          n_perm=1 / unc_pval,
          threshold=unc_pval,
      )
  
      # Calculate uncorrected cluster sizes
      df = len(Y) - X.shape[1]
      neg_log_pval = -np.log10(stats.t.sf(get_data(out["t"]), df=df))
      logp_unc = new_img_like(out["t"], neg_log_pval)
      logp_unc_cluster_sizes = list(
          get_clusters_table(logp_unc, -np.log10(unc_pval))[
              "Cluster Size (mm3)"
          ]
      )
  
      # Calculate corrected cluster sizes
      logp_max_cluster_sizes = list(
          get_clusters_table(out["logp_max_size"], unc_pval)[
              "Cluster Size (mm3)"
          ]
      )
  
      # Compare cluster sizes
      logp_unc_cluster_sizes.sort()
      logp_max_cluster_sizes.sort()
      assert logp_unc_cluster_sizes == logp_max_cluster_sizes
  
      # Test single covariate
      X = pd.DataFrame({"intercept": [1] * len(Y)})
      non_parametric_inference(
          Y,
          design_matrix=X,
          mask=mask,
          model_intercept=False,
          second_level_contrast="intercept",
          n_perm=N_PERM,
          threshold=unc_pval,
      )
  
imports: import os
  from pathlib import Path
  import numpy
  import pandas
  import pytest
  from nibabel import Nifti1Image, load
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
  from scipy import stats
  from nilearn._utils import testing
  from nilearn._utils.data_gen import generate_fake_fmri_data_and_design, write_fake_bold_img, write_fake_fmri_data_and_design
  from nilearn.glm.first_level import FirstLevelModel, run_glm
  from nilearn.glm.second_level import SecondLevelModel, non_parametric_inference
  from nilearn.glm.second_level.second_level import _check_confounds, _check_design_matrix, _check_effect_maps, _check_first_level_contrast, _check_input_as_first_level_model, _check_output_type, _check_second_level_input, _infer_effect_maps, _process_second_level_input_as_dataframe, _process_second_level_input_as_firstlevelmodels, _sort_input_dataframe
  from nilearn.image import concat_imgs, get_data, new_img_like, smooth_img
  from nilearn.maskers import NiftiMasker
label_desc: Use image node_id 41 for calling a global function with example usage: test_non_parametric_inference_cluster_level_with_covariates(tmp_path, rng) without return types