code: def test_bem_model_topology(tmp_path):
      """Test BEM model topological checks."""
      pytest.importorskip("nibabel")
      # bad topology (not enough neighboring tris)
      makedirs(tmp_path / "foo" / "bem")
      for fname in ("inner_skull", "outer_skull", "outer_skin"):
          fname += ".surf"
          copy(
              subjects_dir / "sample" / "bem" / fname,
              tmp_path / "foo" / "bem" / fname,
          )
      outer_fname = tmp_path / "foo" / "bem" / "outer_skull.surf"
      rr, tris = read_surface(outer_fname)
      tris = tris[:-1]
      write_surface(outer_fname, rr, tris[:-1], overwrite=True)
      with pytest.raises(
          RuntimeError, match="Surface outer skull is not compl"
      ):
          make_bem_model("foo", None, subjects_dir=tmp_path)
      # Now get past this error to reach gh-6127 (not enough neighbor tris)
      rr_bad = np.concatenate(
          [rr, np.mean(rr, axis=0, keepdims=True)], axis=0
      )
      write_surface(outer_fname, rr_bad, tris, overwrite=True)
      with pytest.raises(
          ValueError, match="Surface outer skull.*triangles"
      ):
          make_bem_model("foo", None, subjects_dir=tmp_path)
  
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 6 for calling a global function with example usage: test_bem_model_topology(tmp_path) without return types