code: def test_io_bem(tmp_path, ext):
      """Test reading and writing of bem surfaces and solutions."""
      temp_bem = tmp_path / f"temp-bem.{ext}"
      # model
      with pytest.raises(ValueError, match="BEM data not found"):
          read_bem_surfaces(fname_raw)
      with pytest.raises(ValueError, match="surface with id 10"):
          read_bem_surfaces(fname_bem_3, s_id=10)
      surf = read_bem_surfaces(fname_bem_3, patch_stats=True)
      surf = read_bem_surfaces(fname_bem_3, patch_stats=False)
      write_bem_surfaces(temp_bem, surf[0])
      with pytest.raises(OSError, match="exists"):
          write_bem_surfaces(temp_bem, surf[0])
      write_bem_surfaces(temp_bem, surf[0], overwrite=True)
      if ext == "h5":
          import h5py
  
          with h5py.File(temp_bem, "r"):  # make sure it's valid
              pass
      surf_read = read_bem_surfaces(temp_bem, patch_stats=False)
      _compare_bem_surfaces(surf, surf_read)
  
      # solution
      with pytest.raises(RuntimeError, match="No BEM solution found"):
          read_bem_solution(fname_bem_3)
      temp_sol = tmp_path / f"temp-sol.{ext}"
      sol = read_bem_solution(fname_bem_sol_3)
      assert "BEM" in repr(sol)
      write_bem_solution(temp_sol, sol)
      sol_read = read_bem_solution(temp_sol)
      _compare_bem_solutions(sol, sol_read)
      sol = read_bem_solution(fname_bem_sol_1)
      with pytest.raises(
          RuntimeError, match="BEM does not have.*triangulation"
      ):
          _bem_find_surface(sol, 3)
  
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 3 for calling a global function with example usage: test_io_bem(tmp_path, ext) without return types