code: def test_stc_to_label():
      """Test stc_to_label."""
      pytest.importorskip("nibabel")
      pytest.importorskip("sklearn")
      src = read_source_spaces(fwd_fname)
      src_bad = read_source_spaces(src_bad_fname)
      stc = read_source_estimate(stc_fname, "sample")
      os.environ["SUBJECTS_DIR"] = str(data_path / "subjects")
      labels1 = _stc_to_label(stc, src="sample", smooth=3)
      labels2 = _stc_to_label(stc, src=src, smooth=3)
      assert_equal(len(labels1), len(labels2))
      for l1, l2 in zip(labels1, labels2):
          assert_labels_equal(l1, l2, decimal=4)
  
      with pytest.warns(RuntimeWarning, match="have holes"):
          labels_lh, labels_rh = stc_to_label(
              stc, src=src, smooth=True, connected=True
          )
  
      pytest.raises(
          ValueError,
          stc_to_label,
          stc,
          "sample",
          smooth=True,
          connected=True,
      )
      pytest.raises(
          RuntimeError,
          stc_to_label,
          stc,
          smooth=True,
          src=src_bad,
          connected=True,
      )
      assert_equal(len(labels_lh), 1)
      assert_equal(len(labels_rh), 1)
  
      # test getting tris
      tris = labels_lh[0].get_tris(
          src[0]["use_tris"], vertices=stc.vertices[0]
      )
      pytest.raises(
          ValueError, spatial_tris_adjacency, tris, remap_vertices=False
      )
      adjacency = spatial_tris_adjacency(tris, remap_vertices=True)
      assert adjacency.shape[0] == len(stc.vertices[0])
  
      # "src" as a subject name
      pytest.raises(
          TypeError,
          stc_to_label,
          stc,
          src=1,
          smooth=False,
          connected=False,
          subjects_dir=subjects_dir,
      )
      pytest.raises(
          ValueError,
          stc_to_label,
          stc,
          src=SourceSpaces([src[0]]),
          smooth=False,
          connected=False,
          subjects_dir=subjects_dir,
      )
      pytest.raises(
          ValueError,
          stc_to_label,
          stc,
          src="sample",
          smooth=False,
          connected=True,
          subjects_dir=subjects_dir,
      )
      pytest.raises(
          ValueError,
          stc_to_label,
          stc,
          src="sample",
          smooth=True,
          connected=False,
          subjects_dir=subjects_dir,
      )
      labels_lh, labels_rh = stc_to_label(
          stc,
          src="sample",
          smooth=False,
          connected=False,
          subjects_dir=subjects_dir,
      )
      assert len(labels_lh) > 1
      assert len(labels_rh) > 1
  
      # with smooth='patch'
      with pytest.warns(RuntimeWarning, match="have holes"):
          labels_patch = stc_to_label(stc, src=src, smooth=True)
      assert len(labels_patch) == len(labels1)
      for l1, l2 in zip(labels1, labels2):
          assert_labels_equal(l1, l2, decimal=4)
  
imports: import glob
  import os
  import pickle
  import shutil
  from itertools import product
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from scipy import sparse
  from mne import grow_labels, labels_to_stc, morph_labels, random_parcellation, read_label, read_labels_from_annot, read_source_estimate, read_source_spaces, read_surface, spatial_tris_adjacency, split_label, stc_to_label, write_labels_to_annot
  from mne.datasets import testing
  from mne.label import Label, _blend_colors, _load_vert_pos, _n_colors, _read_annot, _read_annot_cands, label_sign_flip, select_sources
  from mne.source_estimate import mesh_edges
  from mne.source_space import SourceSpaces
  from mne.surface import _mesh_borders
  from mne.utils import _record_warnings, get_subjects_dir
label_desc: Use image node_id 17 for calling a global function with example usage: test_stc_to_label() without return types