code: def test_annot_io(tmp_path):
      """Test I/O from and to *.annot files."""
      # copy necessary files from fsaverage to tempdir
      pytest.importorskip("nibabel")
      subject = "fsaverage"
      label_src = subjects_dir / "fsaverage" / "label"
      surf_src = subjects_dir / "fsaverage" / "surf"
      label_dir = tmp_path / subject / "label"
      surf_dir = tmp_path / subject / "surf"
      os.makedirs(label_dir)
      os.mkdir(surf_dir)
      shutil.copy(label_src / "lh.PALS_B12_Lobes.annot", label_dir)
      shutil.copy(label_src / "rh.PALS_B12_Lobes.annot", label_dir)
      shutil.copy(surf_src / "lh.white", surf_dir)
      shutil.copy(surf_src / "rh.white", surf_dir)
  
      # read original labels
      with pytest.raises(OSError, match="\nPALS_B12_Lobes$"):
          read_labels_from_annot(
              subject, "PALS_B12_Lobesey", subjects_dir=tmp_path
          )
      labels = read_labels_from_annot(
          subject, "PALS_B12_Lobes", subjects_dir=tmp_path
      )
  
      # test saving parcellation only covering one hemisphere
      parc = [
          label for label in labels if label.name == "LOBE.TEMPORAL-lh"
      ]
      write_labels_to_annot(
          parc, subject, "myparc", subjects_dir=tmp_path
      )
      parc1 = read_labels_from_annot(
          subject, "myparc", subjects_dir=tmp_path
      )
      parc1 = [
          label
          for label in parc1
          if not label.name.startswith("unknown")
      ]
      assert_equal(len(parc1), len(parc))
      for lt, rt in zip(parc1, parc):
          assert_labels_equal(lt, rt)
  
      # test saving only one hemisphere
      parc = [
          label for label in labels if label.name.startswith("LOBE")
      ]
      write_labels_to_annot(
          parc, subject, "myparc2", hemi="lh", subjects_dir=tmp_path
      )
      annot_fname = tmp_path / subject / "label" / "%sh.myparc2.annot"
      assert Path(str(annot_fname) % "l").is_file()
      assert not Path(str(annot_fname) % "r").is_file()
      parc1 = read_labels_from_annot(
          subject,
          "myparc2",
          annot_fname=str(annot_fname) % "l",
          subjects_dir=tmp_path,
      )
      parc_lh = [label for label in parc if label.name.endswith("lh")]
      for lt, rt in zip(parc1, parc_lh):
          assert_labels_equal(lt, rt)
  
      # test that the annotation is complete (test Label() support)
      rr = read_surface(surf_dir / "lh.white")[0]
      label = sum(labels, Label(hemi="lh", subject="fsaverage")).lh
      assert_array_equal(label.vertices, np.arange(len(rr)))
  
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 10 for calling a global function with example usage: test_annot_io(tmp_path) without return types