code: def test_combine_channels():
      """Test channel combination on Raw, Epochs, and Evoked."""
      raw = read_raw_fif(raw_fname, preload=True)
      raw_ch_bad = read_raw_fif(raw_fname, preload=True)
      raw_ch_bad.info["bads"] = ["MEG 0113", "MEG 0112"]
      epochs = Epochs(raw, read_events(eve_fname))
      evoked = epochs.average()
      good = dict(foo=[0, 1, 3, 4], bar=[5, 2])  # good grad and mag
  
      # Test good cases
      combine_channels(raw, good)
      combined_epochs = combine_channels(epochs, good)
      assert_array_equal(combined_epochs.events, epochs.events)
      assert epochs.baseline == combined_epochs.baseline
      combined_evoked = combine_channels(evoked, good)
      assert evoked.baseline == combined_evoked.baseline
      combine_channels(raw, good, drop_bad=True)
      combine_channels(raw_ch_bad, good, drop_bad=True)
  
      # Test with stimulus channels
      combine_stim = combine_channels(raw, good, keep_stim=True)
      target_nchan = len(good) + len(
          pick_types(raw.info, meg=False, stim=True)
      )
      assert combine_stim.info["nchan"] == target_nchan
  
      # Test results with one ROI
      good_single = dict(foo=[0, 1, 3, 4])  # good grad
      combined_mean = combine_channels(raw, good_single, method="mean")
      combined_median = combine_channels(
          raw, good_single, method="median"
      )
      combined_std = combine_channels(raw, good_single, method="std")
      foo_mean = np.mean(raw.get_data()[good_single["foo"]], axis=0)
      foo_median = np.median(raw.get_data()[good_single["foo"]], axis=0)
      foo_std = np.std(raw.get_data()[good_single["foo"]], axis=0)
      assert_array_equal(
          combined_mean.get_data(), np.expand_dims(foo_mean, axis=0)
      )
      assert_array_equal(
          combined_median.get_data(), np.expand_dims(foo_median, axis=0)
      )
      assert_array_equal(
          combined_std.get_data(), np.expand_dims(foo_std, axis=0)
      )
  
      # Test bad cases
      bad1 = dict(foo=[0, 376], bar=[5, 2])  # out of bounds
      bad2 = dict(foo=[0, 2], bar=[5, 2])  # type mix in same group
      with pytest.raises(
          ValueError, match='"method" must be a callable, or'
      ):
          combine_channels(raw, good, method="bad_method")
      with pytest.raises(
          TypeError, match='"keep_stim" must be of type bool'
      ):
          combine_channels(raw, good, keep_stim="bad_type")
      with pytest.raises(
          TypeError, match='"drop_bad" must be of type bool'
      ):
          combine_channels(raw, good, drop_bad="bad_type")
      with pytest.raises(
          ValueError, match="Some channel indices are out of"
      ):
          combine_channels(raw, bad1)
      with pytest.raises(
          ValueError, match="Cannot combine sensors of diff"
      ):
          combine_channels(raw, bad2)
  
      # Test warnings
      raw_no_stim = read_raw_fif(raw_fname, preload=True)
      raw_no_stim.pick(picks="meg")
      warn1 = dict(
          foo=[375, 375], bar=[5, 2]
      )  # same channel in same group
      warn2 = dict(foo=[375], bar=[5, 2])  # one channel (last channel)
      warn3 = dict(foo=[0, 4], bar=[5, 2])  # one good channel left
      with pytest.warns(
          RuntimeWarning, match="Could not find stimulus"
      ):
          combine_channels(raw_no_stim, good, keep_stim=True)
      with pytest.warns(
          RuntimeWarning, match="Less than 2 channels"
      ) as record:
          combine_channels(raw, warn1)
          combine_channels(raw, warn2)
          combine_channels(raw_ch_bad, warn3, drop_bad=True)
      assert len(record) == 3
  
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 17 for calling a global function with example usage: test_combine_channels() without return types