code: def test_read_ch_adjacency(tmp_path):
      """Test reading channel adjacency templates."""
      a = partial(np.array, dtype="<U7")
      # no pep8
      nbh = np.array(
          [
              [
                  (["MEG0111"], [[a(["MEG0131"])]]),
                  (["MEG0121"], [[a(["MEG0111"])], [a(["MEG0131"])]]),
                  (["MEG0131"], [[a(["MEG0111"])], [a(["MEG0121"])]]),
              ]
          ],
          dtype=[("label", "O"), ("neighblabel", "O")],
      )
      mat = dict(neighbours=nbh)
      mat_fname = tmp_path / "test_mat.mat"
      savemat(mat_fname, mat, oned_as="row")
  
      ch_adjacency, ch_names = read_ch_adjacency(mat_fname)
  
      x = ch_adjacency
      assert_equal(x.shape[0], len(ch_names))
      assert_equal(x.shape, (3, 3))
      assert_equal(x[0, 1], False)
      assert_equal(x[0, 2], True)
      assert np.all(x.diagonal())
      pytest.raises(IndexError, read_ch_adjacency, mat_fname, [0, 3])
      ch_adjacency, ch_names = read_ch_adjacency(
          mat_fname, picks=[0, 2]
      )
      assert_equal(ch_adjacency.shape[0], 2)
      assert_equal(len(ch_names), 2)
  
      ch_names = ["EEG01", "EEG02", "EEG03"]
      neighbors = [["EEG02"], ["EEG04"], ["EEG02"]]
      pytest.raises(
          ValueError, _ch_neighbor_adjacency, ch_names, neighbors
      )
      neighbors = [["EEG02"], ["EEG01", "EEG03"], ["EEG 02"]]
      pytest.raises(
          ValueError, _ch_neighbor_adjacency, ch_names[:2], neighbors
      )
      neighbors = [["EEG02"], "EEG01", ["EEG 02"]]
      pytest.raises(
          ValueError, _ch_neighbor_adjacency, ch_names, neighbors
      )
      adjacency, ch_names = read_ch_adjacency("neuromag306mag")
      assert_equal(adjacency.shape, (102, 102))
      assert_equal(len(ch_names), 102)
      pytest.raises(ValueError, read_ch_adjacency, "bananas!")
  
      # In EGI 256, E31 sensor has no neighbour
      a = partial(np.array)
      nbh = np.array(
          [
              [
                  (["E31"], []),
                  (["E1"], [[a(["E2"])], [a(["E3"])]]),
                  (["E2"], [[a(["E1"])], [a(["E3"])]]),
                  (["E3"], [[a(["E1"])], [a(["E2"])]]),
              ]
          ],
          dtype=[("label", "O"), ("neighblabel", "O")],
      )
      mat = dict(neighbours=nbh)
      mat_fname = tmp_path / "test_isolated_mat.mat"
      savemat(mat_fname, mat, oned_as="row")
      ch_adjacency, ch_names = read_ch_adjacency(mat_fname)
      x = ch_adjacency.todense()
      assert_equal(x.shape[0], len(ch_names))
      assert_equal(x.shape, (4, 4))
      assert np.all(x.diagonal())
      assert not np.any(x[0, 1:])
      assert not np.any(x[1:, 0])
  
      # Check for neighbours consistency. If a sensor is marked as a neighbour,
      # then it should also have its neighbours defined.
      a = partial(np.array)
      nbh = np.array(
          [
              [
                  (["E31"], []),
                  (["E1"], [[a(["E8"])], [a(["E3"])]]),
                  (["E2"], [[a(["E1"])], [a(["E3"])]]),
                  (["E3"], [[a(["E1"])], [a(["E2"])]]),
              ]
          ],
          dtype=[("label", "O"), ("neighblabel", "O")],
      )
      mat = dict(neighbours=nbh)
      mat_fname = tmp_path / "test_error_mat.mat"
      savemat(mat_fname, mat, oned_as="row")
      pytest.raises(ValueError, read_ch_adjacency, mat_fname)
  
imports: import hashlib
  from copy import deepcopy
  from functools import partial
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from scipy.io import savemat
  from mne import Epochs, EpochsArray, EvokedArray, create_info, make_ad_hoc_cov, pick_channels, pick_types, read_events
  from mne._fiff.constants import FIFF, _ch_unit_mul_named
  from mne.channels import combine_channels, equalize_channels, find_ch_adjacency, get_builtin_ch_adjacencies, make_1020_channel_selections, read_ch_adjacency, read_custom_montage, rename_channels
  from mne.channels.channels import _BUILTIN_CHANNEL_ADJACENCIES, _BuiltinChannelAdjacency, _ch_neighbor_adjacency, _compute_ch_adjacency
  from mne.datasets import testing
  from mne.io import RawArray, read_info, read_raw_bti, read_raw_ctf, read_raw_eeglab, read_raw_fif, read_raw_kit
  from mne.parallel import parallel_func
  from mne.utils import requires_good_network
label_desc: Use image node_id 6 for calling a global function with example usage: test_read_ch_adjacency(tmp_path) without return types