code: def test_set_eeg_reference_ch_type(ch_type, msg, projection):
      """Test setting EEG reference for ECoG or DBS."""
      # gh-6454
      # gh-8739 added DBS
      ch_names = ["ECOG01", "ECOG02", "DBS01", "DBS02", "MISC"]
      rng = np.random.RandomState(0)
      data = rng.randn(5, 1000)
      raw = RawArray(
          data,
          create_info(
              ch_names, 1000.0, ["ecog"] * 2 + ["dbs"] * 2 + ["misc"]
          ),
      )
  
      if ch_type == "auto":
          ref_ch = ch_names[:2]
      else:
          ref_ch = raw.copy().pick(picks=ch_type).ch_names
  
      with catch_logging() as log:
          reref, ref_data = set_eeg_reference(
              raw.copy(),
              ch_type=ch_type,
              projection=projection,
              verbose=True,
          )
  
      if not projection:
          assert f"Applying a custom {msg}" in log.getvalue()
          assert reref.info["custom_ref_applied"]  # gh-7350
      _test_reference(raw, reref, ref_data, ref_ch)
      match = (
          "no EEG data found" if projection else "No channels supplied"
      )
      with pytest.raises(ValueError, match=match):
          set_eeg_reference(raw, ch_type="eeg", projection=projection)
      # gh-8739
      raw2 = RawArray(
          data, create_info(5, 1000.0, ["mag"] * 4 + ["misc"])
      )
      with pytest.raises(
          ValueError,
          match="No EEG, ECoG, sEEG or DBS channels "
          "found to rereference.",
      ):
          set_eeg_reference(raw2, ch_type="auto", projection=projection)
  
imports: import itertools
  from contextlib import nullcontext
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from mne import Epochs, Projection, add_reference_channels, create_info, find_events, make_forward_solution, make_sphere_model, pick_channels, pick_channels_forward, pick_types, read_events, read_evokeds, set_bipolar_reference, set_eeg_reference, setup_volume_source_space
  from mne._fiff.constants import FIFF
  from mne._fiff.proj import _has_eeg_average_ref_proj
  from mne._fiff.reference import _apply_reference
  from mne.datasets import testing
  from mne.epochs import BaseEpochs, make_fixed_length_epochs
  from mne.io import RawArray, read_raw_fif
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 4 for calling a global function with example usage: test_set_eeg_reference_ch_type(ch_type, msg, projection) without return types