code: def test_make_scalp_surfaces_topology(tmp_path, monkeypatch):
      """Test topology checks for make_scalp_surfaces."""
      pytest.importorskip("pyvista")
      pytest.importorskip("nibabel")
      subjects_dir = tmp_path
      subject = "test"
      surf_dir = subjects_dir / subject / "surf"
      makedirs(surf_dir)
      surf = _get_ico_surface(2)
      surf["rr"] *= 100  # mm
      write_surface(surf_dir / "lh.seghead", surf["rr"], surf["tris"])
  
      # make it so that decimation really messes up the mesh just by deleting
      # the last N tris
      def _decimate_surface(points, triangles, n_triangles):
          assert len(triangles) >= n_triangles
          return points, triangles[:n_triangles]
  
      monkeypatch.setattr(
          mne.bem, "decimate_surface", _decimate_surface
      )
      # TODO: These two errors should probably have the same class...
  
      # Not enough neighbors
      monkeypatch.setattr(mne.bem, "_tri_levels", dict(sparse=315))
      with pytest.raises(ValueError, match=".*have fewer than three.*"):
          make_scalp_surfaces(
              subject, subjects_dir, force=False, verbose=True
          )
      monkeypatch.setattr(mne.bem, "_tri_levels", dict(sparse=319))
      # Incomplete surface (sum of solid angles)
      with pytest.raises(RuntimeError, match=".*is not complete.*"):
          make_scalp_surfaces(
              subject,
              subjects_dir,
              force=False,
              verbose=True,
              overwrite=True,
          )
      bem_dir = subjects_dir / subject / "bem"
      sparse_path = bem_dir / f"{subject}-head-sparse.fif"
      assert not sparse_path.is_file()
  
      # These are ignorable
      monkeypatch.setattr(mne.bem, "_tri_levels", dict(sparse=315))
      with pytest.warns(
          RuntimeWarning, match=".*have fewer than three.*"
      ):
          make_scalp_surfaces(
              subject, subjects_dir, force=True, overwrite=True
          )
      (surf,) = read_bem_surfaces(sparse_path, on_defects="ignore")
      assert len(surf["tris"]) == 315
      monkeypatch.setattr(mne.bem, "_tri_levels", dict(sparse=319))
      with pytest.warns(RuntimeWarning, match=".*is not complete.*"):
          make_scalp_surfaces(
              subject, subjects_dir, force=True, overwrite=True
          )
      (surf,) = read_bem_surfaces(sparse_path, on_defects="ignore")
      assert len(surf["tris"]) == 319
  
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 10 for calling a global function with example usage: test_make_scalp_surfaces_topology(tmp_path, monkeypatch) and returns: points,  triangles