code: def test_compute_brain_mask():
      img, _ = data_gen.generate_mni_space_img(res=8, random_state=0)
      brain_mask = compute_brain_mask(img, threshold=0.2)
      gm_mask = compute_brain_mask(img, threshold=0.2, mask_type="gm")
      wm_mask = compute_brain_mask(img, threshold=0.2, mask_type="wm")
      brain_data, gm_data, wm_data = map(
          get_data, (brain_mask, gm_mask, wm_mask)
      )
      # Check that whole-brain mask is non-empty
      assert (brain_data != 0).any()
      for subset in gm_data, wm_data:
          # Test that gm and wm masks are included in the whole-brain mask
          assert (
              np.logical_and(brain_data, subset) == subset.astype(bool)
          ).all()
          # Test that gm and wm masks are non-empty
          assert (subset != 0).any()
      # Test that gm and wm masks have empty intersection
      assert (np.logical_and(gm_data, wm_data) == 0).all()
      # Check that we get a useful warning for empty masks
      with pytest.warns(masking._MaskWarning):
          compute_brain_mask(img, threshold=1)
      # Check that masks obtained from same FOV are the same
      img1, _ = data_gen.generate_mni_space_img(res=8, random_state=1)
      mask_img1 = compute_brain_mask(img1, verbose=1, threshold=0.2)
      assert (brain_data == get_data(mask_img1)).all()
      # Check that error is raised if mask type is unknown
      with pytest.raises(ValueError, match="Unknown mask type foo."):
          compute_brain_mask(img, verbose=1, mask_type="foo")
  
imports: import warnings
  import numpy
  import pytest
  from nibabel import Nifti1Image
  from numpy.testing import assert_array_equal
  from sklearn.preprocessing import StandardScaler
  from nilearn import masking
  from nilearn._utils import data_gen
  from nilearn._utils.exceptions import DimensionError
  from nilearn._utils.testing import write_imgs_to_path
  from nilearn.conftest import _rng
  from nilearn.image import get_data, high_variance_confounds
  from nilearn.maskers import NiftiMasker
  from nilearn.masking import _MaskWarning, _unmask_3d, _unmask_4d, compute_background_mask, compute_brain_mask, compute_epi_mask, compute_multi_brain_mask, compute_multi_epi_mask, extrapolate_out_mask, intersect_masks, unmask, unmask_from_to_3d_array
label_desc: Use image node_id 8 for calling a global function with example usage: test_compute_brain_mask() without return types