code: def test_set_channel_types():
      """Test set_channel_types."""
      raw = read_raw_fif(raw_fname)
      # Error Tests
      # Test channel name exists in ch_names
      mapping = {"EEG 160": "EEG060"}
      with pytest.raises(
          ValueError, match=r"name \(EEG 160\) doesn't exist"
      ):
          raw.set_channel_types(mapping)
      # Test change to illegal channel type
      mapping = {"EOG 061": "xxx"}
      with pytest.raises(
          ValueError, match="cannot change to this channel type"
      ):
          raw.set_channel_types(mapping)
      # Test changing type if in proj
      mapping = {
          "EEG 057": "dbs",
          "EEG 058": "ecog",
          "EEG 059": "ecg",
          "EEG 060": "eog",
          "EOG 061": "seeg",
          "MEG 2441": "eeg",
          "MEG 2443": "eeg",
          "MEG 2442": "hbo",
          "EEG 001": "resp",
      }
      raw2 = read_raw_fif(raw_fname)
      raw2.info["bads"] = ["EEG 059", "EEG 060", "EOG 061"]
      with pytest.raises(
          RuntimeError, match='type .* in projector "PCA-v1"'
      ):
          raw2.set_channel_types(mapping)  # has prj
      raw2.add_proj([], remove_existing=True)
  
      # Should raise
      with pytest.raises(
          ValueError, match="unit for channel.* has changed"
      ):
          raw2.copy().set_channel_types(mapping, on_unit_change="raise")
  
      # Should warn
      with pytest.warns(
          RuntimeWarning, match="unit for channel.* has changed"
      ):
          raw2.copy().set_channel_types(mapping)
  
      # Shouldn't warn
      raw2.set_channel_types(mapping, on_unit_change="ignore")
  
      info = raw2.info
      assert info["chs"][371]["ch_name"] == "EEG 057"
      assert info["chs"][371]["kind"] == FIFF.FIFFV_DBS_CH
      assert info["chs"][371]["unit"] == FIFF.FIFF_UNIT_V
      assert info["chs"][371]["coil_type"] == FIFF.FIFFV_COIL_EEG
      assert info["chs"][372]["ch_name"] == "EEG 058"
      assert info["chs"][372]["kind"] == FIFF.FIFFV_ECOG_CH
      assert info["chs"][372]["unit"] == FIFF.FIFF_UNIT_V
      assert info["chs"][372]["coil_type"] == FIFF.FIFFV_COIL_EEG
      assert info["chs"][373]["ch_name"] == "EEG 059"
      assert info["chs"][373]["kind"] == FIFF.FIFFV_ECG_CH
      assert info["chs"][373]["unit"] == FIFF.FIFF_UNIT_V
      assert info["chs"][373]["coil_type"] == FIFF.FIFFV_COIL_NONE
      assert info["chs"][374]["ch_name"] == "EEG 060"
      assert info["chs"][374]["kind"] == FIFF.FIFFV_EOG_CH
      assert info["chs"][374]["unit"] == FIFF.FIFF_UNIT_V
      assert info["chs"][374]["coil_type"] == FIFF.FIFFV_COIL_NONE
      assert info["chs"][375]["ch_name"] == "EOG 061"
      assert info["chs"][375]["kind"] == FIFF.FIFFV_SEEG_CH
      assert info["chs"][375]["unit"] == FIFF.FIFF_UNIT_V
      assert info["chs"][375]["coil_type"] == FIFF.FIFFV_COIL_EEG
      for idx in pick_channels(
          raw.ch_names, ["MEG 2441", "MEG 2443"], ordered=False
      ):
          assert info["chs"][idx]["kind"] == FIFF.FIFFV_EEG_CH
          assert info["chs"][idx]["unit"] == FIFF.FIFF_UNIT_V
          assert info["chs"][idx]["coil_type"] == FIFF.FIFFV_COIL_EEG
      idx = pick_channels(raw.ch_names, ["MEG 2442"])[0]
      assert info["chs"][idx]["kind"] == FIFF.FIFFV_FNIRS_CH
      assert info["chs"][idx]["unit"] == FIFF.FIFF_UNIT_MOL
      assert info["chs"][idx]["coil_type"] == FIFF.FIFFV_COIL_FNIRS_HBO
  
      # resp channel type
      idx = pick_channels(raw.ch_names, ["EEG 001"])[0]
      assert info["chs"][idx]["kind"] == FIFF.FIFFV_RESP_CH
      assert info["chs"][idx]["unit"] == FIFF.FIFF_UNIT_V
      assert info["chs"][idx]["coil_type"] == FIFF.FIFFV_COIL_NONE
  
      # Test meaningful error when setting channel type with unknown unit
      raw.info["chs"][0]["unit"] = 0.0
      ch_types = {raw.ch_names[0]: "misc"}
      pytest.raises(ValueError, raw.set_channel_types, ch_types)
  
      # test reset of channel units on unit change
      idx = raw.ch_names.index("EEG 003")
      raw.info["chs"][idx]["unit_mul"] = _ch_unit_mul_named[-6]
      assert raw.info["chs"][idx]["unit_mul"] == -6
      raw.set_channel_types(
          {"EEG 003": "misc"}, on_unit_change="ignore"
      )
      assert raw.info["chs"][idx]["unit_mul"] == 0
  
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 3 for calling a global function with example usage: test_set_channel_types() without return types