code: def test_has_eeg_average_ref_proj(ch_type):
      """Test checking whether an (i)EEG average reference exists."""
      all_ref_ch_types = list(_EEG_AVREF_PICK_DICT)
      if ch_type == "all":
          ch_types = all_ref_ch_types
          set_eeg_ref_ch_type = all_ref_ch_types
      else:
          ch_types = [ch_type] * len(all_ref_ch_types)
          set_eeg_ref_ch_type = ch_type
      empty_info = create_info(len(all_ref_ch_types), 1000.0, ch_types)
      assert not _has_eeg_average_ref_proj(empty_info)
  
      raw = read_raw_fif(raw_fname)
      raw.del_proj()
      raw.load_data()
      picks = pick_types(raw.info, eeg=True)
      assert len(picks) == 60
      # repeat `ch_types` over and over again
      ch_types = sum(
          [ch_types] * (len(picks) // len(ch_types) + 1), []
      )[: len(picks)]
      raw.set_channel_types(
          {
              raw.ch_names[pick]: ch_type
              for pick, ch_type in zip(picks, ch_types)
          }
      )
      raw._data[picks] = 1.0  # set all to unity
      # For individual channel types, set them and return from the test early
      if ch_type != "all":
          for ch_type in ("auto", set_eeg_ref_ch_type):
              raw.set_eeg_reference(projection=True, ch_type=ch_type)
              assert len(raw.info["projs"]) == 1
              assert _has_eeg_average_ref_proj(raw.info)
              assert not _needs_eeg_average_ref_proj(raw.info)
              if ch_type == "auto":
                  with pytest.warns(
                      RuntimeWarning, match="added.*untouched"
                  ):
                      raw.set_eeg_reference(
                          projection=True, ch_type=ch_type
                      )
                  raw.del_proj()
          desc = raw.info["projs"][0]["desc"].lower()
          assert ch_type in desc
          data = raw.copy().apply_proj()[picks][0]
          assert_allclose(data, 0.0, atol=1e-12)  # zeroed out
          return
  
      # Now for ch_type == 'all', ensure that we can make one proj or
      # len(all_ref_ch_types) projs
  
      # One big joint proj
      raw.set_eeg_reference(
          projection=True, ch_type=set_eeg_ref_ch_type
      )
      assert len(raw.info["projs"]) == len(all_ref_ch_types)
      raw.del_proj()
      raw.set_eeg_reference(
          projection=True, ch_type=set_eeg_ref_ch_type, joint=True
      )
      assert len(raw.info["projs"]) == 1
      assert _has_eeg_average_ref_proj(raw.info)
      assert not _needs_eeg_average_ref_proj(raw.info)
      desc = raw.info["projs"][0]["desc"].lower()
      assert all(ch_type in desc for ch_type in all_ref_ch_types)
      for ch_type in all_ref_ch_types + [all_ref_ch_types]:
          with pytest.warns(
              RuntimeWarning, match="already added.*untouch"
          ):
              raw.set_eeg_reference(projection=True, ch_type=ch_type)
      data = raw.copy().apply_proj()[picks][0]
      assert_allclose(data, 0.0, atol=1e-12)  # zeroed out
      raw.del_proj()
  
      # len(all_kinds) separate projs, with data for each channel type that
      # is a different non-zero integer (EEG=1, SEEG=2, ...)
      for ci, ch_type in enumerate(all_ref_ch_types):
          raw._data[pick_types(raw.info, **{ch_type: True})] = ci + 1
      for ci, ch_type in enumerate(all_ref_ch_types):
          raw.set_eeg_reference(projection=True, ch_type=ch_type)
          assert len(raw.info["projs"]) == ci + 1
          if ci < len(all_ref_ch_types) < 1:
              assert not _has_eeg_average_ref_proj(raw.info)
              assert _needs_eeg_average_ref_proj(raw.info)
      assert len(raw.info["projs"]) == len(all_ref_ch_types)
      assert _has_eeg_average_ref_proj(raw.info)
      assert not _needs_eeg_average_ref_proj(raw.info)
      descs = [p["desc"].lower() for p in raw.info["projs"]]
      assert len(descs) == len(all_ref_ch_types)
      for desc, ch_type in zip(descs, all_ref_ch_types):
          assert ch_type in desc
      assert_allclose(
          raw[picks][0], raw[all_ref_ch_types][0], atol=1e-12
      )
      data = raw.copy().apply_proj()[picks][0]
      assert len(data) == len(picks)
      assert_allclose(data, 0.0, atol=1e-12)  # zeroed out
      # a single joint proj will *not* zero out given these integer 1/2/3...
      # values per channel type assuming we have an even number of channels.
      # If this changes we'll have to make this check better
      assert len(all_ref_ch_types) % 2 == 0
      data_nz = (
          raw.del_proj()
          .set_eeg_reference(
              projection=True, ch_type=all_ref_ch_types, joint=True
          )
          .apply_proj()[picks][0]
      )
      assert not np.isclose(data_nz, 0.0).any()
  
imports: import copy
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_equal
  from scipy import linalg
  from mne import Epochs, compute_proj_epochs, compute_proj_evoked, compute_proj_raw, compute_raw_covariance, convert_forward_solution, create_info, pick_types, read_events, read_forward_solution, read_source_estimate, sensitivity_map
  from mne._fiff.proj import _EEG_AVREF_PICK_DICT, _needs_eeg_average_ref_proj, activate_proj, make_projector, setup_proj
  from mne.cov import compute_whitener, regularize
  from mne.datasets import testing
  from mne.io import RawArray, read_raw_fif
  from mne.preprocessing import maxwell_filter
  from mne.proj import _has_eeg_average_ref_proj, make_eeg_average_ref_proj, read_proj, write_proj
  from mne.rank import _compute_rank_int
  from mne.utils import _record_warnings
label_desc: Use image node_id 8 for calling a global function with example usage: test_has_eeg_average_ref_proj(ch_type) without return types