code: def test_cov_order():
      """Test covariance ordering."""
      raw = read_raw_fif(raw_fname)
      raw.set_eeg_reference(projection=True)
      info = raw.info
      # add MEG channel with low enough index number to affect EEG if
      # order is incorrect
      info["bads"] += ["MEG 0113"]
      ch_names = [
          info["ch_names"][pick]
          for pick in pick_types(info, meg=False, eeg=True)
      ]
      cov = read_cov(cov_fname)
      # no avg ref present warning
      prepare_noise_cov(cov, info, ch_names, verbose="error")
      # big reordering
      cov_reorder = cov.copy()
      order = np.random.RandomState(0).permutation(
          np.arange(len(cov.ch_names))
      )
      cov_reorder["names"] = [cov["names"][ii] for ii in order]
      cov_reorder["data"] = cov["data"][order][:, order]
      # Make sure we did this properly
      _assert_reorder(cov_reorder, cov, order)
      # Now check some functions that should get the same result for both
      # regularize
      with pytest.raises(ValueError, match="rank, if str"):
          regularize(cov, info, rank="foo")
      with pytest.raises(TypeError, match="rank must be"):
          regularize(cov, info, rank=False)
      with pytest.raises(TypeError, match="rank must be"):
          regularize(cov, info, rank=1.0)
      cov_reg = regularize(cov, info, rank="full")
      cov_reg_reorder = regularize(cov_reorder, info, rank="full")
      _assert_reorder(cov_reg_reorder, cov_reg, order)
      # prepare_noise_cov
      cov_prep = prepare_noise_cov(cov, info, ch_names)
      cov_prep_reorder = prepare_noise_cov(cov, info, ch_names)
      _assert_reorder(
          cov_prep,
          cov_prep_reorder,
          order=np.arange(len(cov_prep["names"])),
      )
      # compute_whitener
      whitener, w_ch_names, n_nzero = compute_whitener(
          cov, info, return_rank=True
      )
      assert whitener.shape[0] == whitener.shape[1]
      whitener_2, w_ch_names_2, n_nzero_2 = compute_whitener(
          cov_reorder, info, return_rank=True
      )
      assert_array_equal(w_ch_names_2, w_ch_names)
      assert_allclose(whitener_2, whitener, rtol=1e-6)
      assert n_nzero == n_nzero_2
      # with pca
      assert n_nzero < whitener.shape[0]
      whitener_pca, w_ch_names_pca, n_nzero_pca = compute_whitener(
          cov, info, pca=True, return_rank=True
      )
      assert_array_equal(w_ch_names_pca, w_ch_names)
      assert n_nzero_pca == n_nzero
      assert whitener_pca.shape == (n_nzero_pca, len(w_ch_names))
      # whiten_evoked
      evoked = read_evokeds(ave_fname)[0]
      evoked_white = whiten_evoked(evoked, cov)
      evoked_white_2 = whiten_evoked(evoked, cov_reorder)
      assert_allclose(evoked_white_2.data, evoked_white.data, atol=1e-7)
  
imports: import itertools
  import sys
  from inspect import signature
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import Epochs, compute_covariance, compute_proj_raw, compute_rank, compute_raw_covariance, create_info, find_events, make_ad_hoc_cov, make_fixed_length_events, merge_events, pick_channels_cov, pick_info, pick_types, read_cov, read_evokeds, write_cov
  from mne._fiff.pick import _DATA_CH_TYPES_SPLIT
  from mne.channels import equalize_channels
  from mne.cov import _auto_low_rank_model, _regularized_covariance, compute_whitener, prepare_noise_cov, regularize, whiten_evoked
  from mne.datasets import testing
  from mne.fixes import _safe_svd
  from mne.io import RawArray, read_info, read_raw_ctf, read_raw_fif
  from mne.preprocessing import maxwell_filter
  from mne.rank import _compute_rank_int
  from mne.utils import _record_warnings, assert_snr, catch_logging
label_desc: Use image node_id 3 for calling a global function with example usage: test_cov_order() without return types