code: def test_io_head_bem(tmp_path):
      """Test reading and writing of defective head surfaces."""
      head = read_bem_surfaces(fname_dense_head)[0]
      fname_defect = tmp_path / "temp-head-defect.fif"
      # create defects
      head["rr"][0] = np.array([-0.01487014, -0.04563854, -0.12660208])
      head["tris"][0] = np.array([21919, 21918, 21907])
  
      with pytest.raises(ValueError, match="topological defects:"):
          write_head_bem(fname_defect, head["rr"], head["tris"])
      with pytest.warns(RuntimeWarning, match="topological defects:"):
          write_head_bem(
              fname_defect, head["rr"], head["tris"], on_defects="warn"
          )
      # test on_defects in read_bem_surfaces
      with pytest.raises(ValueError, match="topological defects:"):
          read_bem_surfaces(fname_defect)
      with pytest.warns(RuntimeWarning, match="topological defects:"):
          head_defect = read_bem_surfaces(
              fname_defect, on_defects="warn"
          )[0]
  
      assert (
          head["id"] == head_defect["id"] == FIFF.FIFFV_BEM_SURF_ID_HEAD
      )
      assert np.allclose(head["rr"], head_defect["rr"])
      assert np.allclose(head["tris"], head_defect["tris"])
  
imports: import re
  from copy import deepcopy
  from os import makedirs
  from pathlib import Path
  from shutil import copy
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_equal
  import mne
  from mne import Info, Transform, make_bem_model, make_bem_solution, make_sphere_model, read_bem_solution, read_bem_surfaces, write_bem_solution, write_bem_surfaces, write_head_bem, write_surface
  from mne._fiff.constants import FIFF
  from mne.bem import _assert_complete_surface, _assert_inside, _bem_find_surface, _check_surface_size, _get_ico_map, _ico_downsample, _order_surfaces, distance_to_bem, fit_sphere_to_headshape, make_scalp_surfaces
  from mne.datasets import testing
  from mne.io import read_info
  from mne.surface import _get_ico_surface, read_surface
  from mne.transforms import translation
  from mne.utils import catch_logging, check_version
label_desc: Use image node_id 9 for calling a global function with example usage: test_io_head_bem(tmp_path) without return types