code: def test_bad_channels(method, allow_ref_meg):
      """Test exception when unsupported channels are used."""
      _skip_check_picard(method)
      chs = list(get_channel_type_constants())
      info = create_info(len(chs), 500, chs)
      rng = np.random.RandomState(0)
      data = rng.rand(len(chs), 50)
      raw = RawArray(data, info)
      data = rng.rand(100, len(chs), 50)
      epochs = EpochsArray(data, info)
  
      # fake high-pass filtering
      with raw.info._unlock():
          raw.info["highpass"] = 1.0
      with epochs.info._unlock():
          epochs.info["highpass"] = 1.0
  
      n_components = 0.9
      data_chs = list(_DATA_CH_TYPES_SPLIT + ("eog",))
      if allow_ref_meg:
          data_chs.append("ref_meg")
      chs_bad = list(set(chs) - set(data_chs))
      ica = ICA(
          n_components=n_components,
          method=method,
          allow_ref_meg=allow_ref_meg,
      )
      for inst in [raw, epochs]:
          for ch in chs_bad:
              picks_dict = {
                  (
                      "eyetrack"
                      if ch in ("eyegaze", "pupil")
                      else str(ch)
                  ): True
              }
              if allow_ref_meg:
                  # Test case for only bad channels
                  picks_bad1 = pick_types(
                      inst.info, meg=False, ref_meg=False, **picks_dict
                  )
                  # Test case for good and bad channels
                  picks_bad2 = pick_types(
                      inst.info, meg=True, ref_meg=True, **picks_dict
                  )
              else:
                  # Test case for only bad channels
                  picks_bad1 = pick_types(
                      inst.info, meg=False, **picks_dict
                  )
                  # Test case for good and bad channels
                  picks_bad2 = pick_types(
                      inst.info, meg=True, **picks_dict
                  )
  
              with pytest.raises(
                  ValueError, match="Invalid channel type"
              ):
                  ica.fit(inst, picks=picks_bad1)
                  ica.fit(inst, picks=picks_bad2)
          with pytest.raises(
              ValueError, match="No appropriate channels found"
          ):
              ica.fit(inst, picks=[])
  
imports: import os
  import shutil
  from contextlib import nullcontext
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy import linalg, stats
  from scipy.io import loadmat, savemat
  from mne import Annotations, Epochs, EpochsArray, EvokedArray, Info, create_info, make_ad_hoc_cov, pick_channels_regexp, pick_types, read_events
  from mne._fiff.pick import _DATA_CH_TYPES_SPLIT, get_channel_type_constants
  from mne.cov import read_cov
  from mne.datasets import testing
  from mne.event import make_fixed_length_events
  from mne.io import RawArray, read_raw_ctf, read_raw_eeglab, read_raw_fif
  from mne.io.eeglab.eeglab import _check_load_mat
  from mne.preprocessing import ICA
  from mne.preprocessing import ica_find_ecg_events, ica_find_eog_events, read_ica
  from mne.preprocessing.ica import _ica_explained_variance, _sort_components, corrmap, get_score_funcs, read_ica_eeglab
  from mne.rank import _compute_rank_int
  from mne.utils import _record_warnings, catch_logging, check_version
label_desc: Use image node_id 21 for calling a global function with example usage: test_bad_channels(method, allow_ref_meg) without return types