code: def test_setup_source_space(tmp_path):
      """Test setting up ico, oct, and all source spaces."""
      pytest.importorskip("nibabel")
      fname_ico = (
          data_path
          / "subjects"
          / "fsaverage"
          / "bem"
          / "fsaverage-ico-5-src.fif"
      )
      # first lets test some input params
      for spacing in ("oct", "oct6e"):
          with pytest.raises(
              ValueError, match="subdivision must be an integer"
          ):
              setup_source_space(
                  "sample",
                  spacing=spacing,
                  add_dist=False,
                  subjects_dir=subjects_dir,
              )
      for spacing in ("oct0", "oct-4"):
          with pytest.raises(
              ValueError, match="oct subdivision must be >= 1"
          ):
              setup_source_space(
                  "sample",
                  spacing=spacing,
                  add_dist=False,
                  subjects_dir=subjects_dir,
              )
      with pytest.raises(
          ValueError, match="ico subdivision must be >= 0"
      ):
          setup_source_space(
              "sample",
              spacing="ico-4",
              add_dist=False,
              subjects_dir=subjects_dir,
          )
      with pytest.raises(
          ValueError, match="must be a string with values"
      ):
          setup_source_space(
              "sample",
              spacing="7emm",
              add_dist=False,
              subjects_dir=subjects_dir,
          )
      with pytest.raises(
          ValueError, match="must be a string with values"
      ):
          setup_source_space(
              "sample",
              spacing="ally",
              add_dist=False,
              subjects_dir=subjects_dir,
          )
  
      # ico 5 (fsaverage) - write to temp file
      src = read_source_spaces(fname_ico)
      with _record_warnings():  # sklearn equiv neighbors
          src_new = setup_source_space(
              "fsaverage",
              spacing="ico5",
              subjects_dir=subjects_dir,
              add_dist=False,
          )
      _compare_source_spaces(src, src_new, mode="approx")
      assert repr(src).split("~")[0] == repr(src_new).split("~")[0]
      assert repr(src).count("surface (") == 2
      assert_array_equal(src[0]["vertno"], np.arange(10242))
      assert_array_equal(src[1]["vertno"], np.arange(10242))
  
      # oct-6 (sample) - auto filename + IO
      src = read_source_spaces(fname)
      temp_name = tmp_path / "temp-src.fif"
      with _record_warnings():  # sklearn equiv neighbors
          src_new = setup_source_space(
              "sample",
              spacing="oct6",
              subjects_dir=subjects_dir,
              add_dist=False,
          )
          write_source_spaces(temp_name, src_new, overwrite=True)
      assert_equal(src_new[0]["nuse"], 4098)
      _compare_source_spaces(src, src_new, mode="approx", nearest=False)
      src_new = read_source_spaces(temp_name)
      _compare_source_spaces(src, src_new, mode="approx", nearest=False)
  
      # all source points - no file writing
      src_new = setup_source_space(
          "sample",
          spacing="all",
          subjects_dir=subjects_dir,
          add_dist=False,
      )
      assert src_new[0]["nuse"] == len(src_new[0]["rr"])
      assert src_new[1]["nuse"] == len(src_new[1]["rr"])
  
      # dense source space to hit surf['inuse'] lines of _create_surf_spacing
      pytest.raises(
          RuntimeError,
          setup_source_space,
          "sample",
          spacing="ico6",
          subjects_dir=subjects_dir,
          add_dist=False,
      )
  
imports: from pathlib import Path
  from shutil import copytree
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less, assert_equal
  import mne
  from mne import SourceEstimate, add_source_space_distances, compute_source_morph, get_volume_labels_from_src, make_sphere_model, morph_source_spaces, pick_types, read_bem_solution, read_bem_surfaces, read_freesurfer_lut, read_source_spaces, read_trans, setup_source_space, setup_volume_source_space, write_source_spaces
  from mne._fiff.constants import FIFF
  from mne._fiff.pick import _picks_to_idx
  from mne.datasets import testing
  from mne.fixes import _get_img_fdata
  from mne.source_estimate import _get_src_type
  from mne.source_space import compute_distance_to_sensors, get_decimated_surfaces
  from mne.source_space._source_space import _compare_source_spaces
  from mne.surface import _accumulate_normals, _triangle_neighbors
  from mne.utils import _record_warnings, requires_mne, run_subprocess
label_desc: Use image node_id 12 for calling a global function with example usage: test_setup_source_space(tmp_path) without return types