code: def test_get_dataset_dir(tmp_path):
      # testing folder creation under different environments, enforcing
      # a custom clean install
      os.environ.pop("NILEARN_DATA", None)
      os.environ.pop("NILEARN_SHARED_DATA", None)
  
      expected_base_dir = os.path.expanduser("~/nilearn_data")
      data_dir = _utils.get_dataset_dir("test", verbose=0)
  
      assert data_dir == os.path.join(expected_base_dir, "test")
      assert os.path.exists(data_dir)
  
      shutil.rmtree(data_dir)
  
      expected_base_dir = str(tmp_path / "test_nilearn_data")
      os.environ["NILEARN_DATA"] = expected_base_dir
      data_dir = _utils.get_dataset_dir("test", verbose=0)
  
      assert data_dir == os.path.join(expected_base_dir, "test")
      assert os.path.exists(data_dir)
  
      shutil.rmtree(data_dir)
  
      expected_base_dir = str(tmp_path / "nilearn_shared_data")
      os.environ["NILEARN_SHARED_DATA"] = expected_base_dir
      data_dir = _utils.get_dataset_dir("test", verbose=0)
  
      assert data_dir == os.path.join(expected_base_dir, "test")
      assert os.path.exists(data_dir)
  
      shutil.rmtree(data_dir)
  
      # Verify exception for a path which exists and is a file
      test_file = str(tmp_path / "some_file")
      with open(test_file, "w") as out:
          out.write("abcfeg")
  
      with pytest.raises(
          OSError,
          match="Nilearn tried to store the dataset in the following "
          "directories, but",
      ):
          _utils.get_dataset_dir("test", test_file, verbose=0)
  
imports: import contextlib
  import gzip
  import os
  import shutil
  import tarfile
  import urllib
  import zipfile
  from tempfile import mkdtemp, mkstemp
  from unittest.mock import MagicMock
  import numpy
  import pytest
  import requests
  from nilearn.datasets import _utils
  from nilearn.datasets import utils
label_desc: Use image node_id 3 for calling a global function with example usage: test_get_dataset_dir(tmp_path) without return types