code: def test_bem_solution(tmp_path, cond, fname):
      """Test making a BEM solution from Python and OpenMEEG with I/O."""
      pytest.importorskip("nibabel")
      # test degenerate conditions
      surf = read_bem_surfaces(fname_bem_1)[0]
      with pytest.raises(RuntimeError, match="2 or less"):
          _ico_downsample(surf, 10)
      s_bad = dict(
          tris=surf["tris"][1:], ntri=surf["ntri"] - 1, rr=surf["rr"]
      )
      with pytest.raises(
          RuntimeError, match="Cannot decimate.*isomorphic"
      ):
          _ico_downsample(s_bad, 1)
      s_bad = dict(
          tris=surf["tris"].copy(), ntri=surf["ntri"], rr=surf["rr"]
      )  # bad triangulation
      s_bad["tris"][0] = [0, 0, 0]
      with pytest.raises(RuntimeError, match="ordering is wrong"):
          _ico_downsample(s_bad, 1)
      s_bad["id"] = 1
      with pytest.raises(RuntimeError, match="is not complete"):
          _assert_complete_surface(s_bad)
      s_bad = dict(
          tris=surf["tris"], ntri=surf["ntri"], rr=surf["rr"].copy()
      )
      s_bad["rr"][0] = 0.0
      with pytest.raises(RuntimeError, match="No matching vertex"):
          _get_ico_map(surf, s_bad)
  
      surfs = read_bem_surfaces(fname_bem_3)
      with pytest.raises(
          RuntimeError, match="is not completely inside"
      ):
          _assert_inside(surfs[0], surfs[1])  # outside
      surfs[0]["id"] = 100  # bad surfs
      with pytest.raises(RuntimeError, match="bad surface id"):
          _order_surfaces(surfs)
      surfs[1]["rr"] /= 1000.0
      with pytest.raises(RuntimeError, match="seem too small"):
          _check_surface_size(surfs[1])
  
      # actually test functionality
      fname_temp = tmp_path / "temp-bem-sol.fif"
      # use a model and solution made in Python
      for model_type in ("python", "c"):
          if model_type == "python":
              model = make_bem_model(
                  "sample",
                  conductivity=cond,
                  ico=2,
                  subjects_dir=subjects_dir,
              )
          else:
              model = fname_bem_1 if len(cond) == 1 else fname_bem_3
      solution = make_bem_solution(model, verbose=True)
      assert solution["solver"] == "mne"
      solution_c = read_bem_solution(fname)
      assert solution_c["solver"] == "mne"
      _compare_bem_solutions(solution, solution_c)
      write_bem_solution(fname_temp, solution)
      solution_read = read_bem_solution(fname_temp)
      assert solution["solver"] == solution_c["solver"] == "mne"
      assert solution_read["solver"] == "mne"
      _compare_bem_solutions(solution, solution_c)
      _compare_bem_solutions(solution_read, solution_c)
      # OpenMEEG
      pytest.importorskip(
          "openmeeg",
          "2.5",
          reason="OpenMEEG required to fully test BEM "
          "solution computation",
      )
      with catch_logging() as log:
          solution = make_bem_solution(
              model, solver="openmeeg", verbose=True
          )
      log = log.getvalue()
      assert "OpenMEEG" in log
      write_bem_solution(fname_temp, solution, overwrite=True)
      solution_read = read_bem_solution(fname_temp)
      assert solution["solver"] == solution_read["solver"] == "openmeeg"
      _compare_bem_solutions(solution_read, solution)
  
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 7 for calling a global function with example usage: test_bem_solution(tmp_path, cond, fname) without return types