code: def test_discrete_source_space(tmp_path):
      """Test setting up (and reading/writing) discrete source spaces."""
      pytest.importorskip("nibabel")
      src = read_source_spaces(fname)
      v = src[0]["vertno"]
  
      # let's make a discrete version with the C code, and with ours
      temp_name = tmp_path / "temp-src.fif"
      # save
      temp_pos = tmp_path / "temp-pos.txt"
      np.savetxt(str(temp_pos), np.c_[src[0]["rr"][v], src[0]["nn"][v]])
      # let's try the spherical one (no bem or surf supplied)
      run_subprocess(
          [
              "mne_volume_source_space",
              "--meters",
              "--pos",
              temp_pos,
              "--src",
              temp_name,
          ]
      )
      src_c = read_source_spaces(temp_name)
      pos_dict = dict(rr=src[0]["rr"][v], nn=src[0]["nn"][v])
      src_new = setup_volume_source_space(pos=pos_dict)
      assert src_new.kind == "discrete"
      _compare_source_spaces(src_c, src_new, mode="approx")
      assert_allclose(
          src[0]["rr"][v], src_new[0]["rr"], rtol=1e-3, atol=1e-6
      )
      assert_allclose(
          src[0]["nn"][v], src_new[0]["nn"], rtol=1e-3, atol=1e-6
      )
  
      # now do writing
      write_source_spaces(temp_name, src_c, overwrite=True)
      src_c2 = read_source_spaces(temp_name)
      _compare_source_spaces(src_c, src_c2)
  
      # now do MRI
      with pytest.raises(
          ValueError, match="Cannot create interpolation"
      ):
          setup_volume_source_space(
              "sample", pos=pos_dict, mri=fname_mri
          )
      assert repr(src_new).split("~")[0] == repr(src_c).split("~")[0]
      assert " kB" in repr(src_new)
      assert src_new.kind == "discrete"
      assert _get_src_type(src_new, None) == "discrete"
  
      with pytest.raises(RuntimeError, match="finite"):
          setup_volume_source_space(
              pos=dict(rr=[[0, 0, float("inf")]], nn=[[0, 1, 0]])
          )
  
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 7 for calling a global function with example usage: test_discrete_source_space(tmp_path) without return types