code: def test_downloader(tmp_path, request_mocker):
      # Sandboxing test
      # ===============
  
      # When nilearn downloads a file, everything is first downloaded in a
      # temporary directory (sandbox) and moved to the "real" data directory if
      # all files are present. In case of error, the sandbox is deleted.
  
      # To test this feature, we do as follow:
      # - create the data dir with a file that has a specific content
      # - try to download the dataset but make it fail
      #   on purpose (by requesting a file that is not in the archive)
      # - check that the previously created file is untouched :
      #   - if sandboxing is faulty, the file would be replaced
      #     by the file of the archive
      #   - if sandboxing works, the file must be untouched.
  
      local_archive = (
          Path(__file__).parent
          / "data"
          / "craddock_2011_parcellations.tar.gz"
      )
      url = "http://example.com/craddock_atlas"
      request_mocker.url_mapping["*craddock*"] = local_archive
      datasetdir = tmp_path / "craddock_2012"
      datasetdir.mkdir()
  
      # Create a dummy file. If sandboxing is successful, it won't be overwritten
      dummy_file = datasetdir / "random_all.nii.gz"
      with dummy_file.open("w") as f:
          f.write("stuff")
  
      opts = {"uncompress": True}
      files = [
          ("random_all.nii.gz", url, opts),
          # The following file does not exists. It will cause an abortion of
          # the fetching procedure
          ("bald.nii.gz", url, opts),
      ]
  
      with pytest.raises(IOError):
          fetch_files(
              str(tmp_path / "craddock_2012"),
              files,
              verbose=0,
          )
      with dummy_file.open("r") as f:
          stuff = f.read(5)
      assert stuff == "stuff"
  
      # Downloading test
      # ================
  
      # Now, we use the regular downloading feature. This will override the dummy
      # file created before.
  
      atlas.fetch_atlas_craddock_2012(data_dir=tmp_path)
      with dummy_file.open() as f:
          stuff = f.read()
      assert stuff == ""
  
imports: import itertools
  import os
  import re
  from pathlib import Path
  import nibabel
  import numpy
  import pandas
  import pytest
  from numpy.testing import assert_array_equal
  from nilearn._utils import data_gen
  from nilearn._utils.testing import serialize_niimg
  from nilearn.conftest import _rng
  from nilearn.datasets import atlas
  from nilearn.datasets._utils import fetch_files
  from nilearn.datasets.tests._testing import dict_to_archive
  from nilearn.image import get_data
label_desc: Use image node_id 1 for calling a global function with example usage: test_downloader(tmp_path, request_mocker) without return types