code: def test_cov_estimation_on_raw(method, tmp_path):
      """Test estimation from raw (typically empty room)."""
      if method == "shrunk":
          try:
              import sklearn  # noqa: F401
          except Exception as exp:
              pytest.skip("sklearn is required, got %s" % (exp,))
      raw = read_raw_fif(raw_fname, preload=True)
      cov_mne = read_cov(erm_cov_fname)
      method_params = dict(shrunk=dict(shrinkage=[0]))
  
      # The pure-string uses the more efficient numpy-based method, the
      # the list gets triaged to compute_covariance (should be equivalent
      # but use more memory)
      with _record_warnings():  # can warn about EEG ref
          cov = compute_raw_covariance(
              raw,
              tstep=None,
              method=method,
              rank="full",
              method_params=method_params,
          )
      assert_equal(cov.ch_names, cov_mne.ch_names)
      assert_equal(cov.nfree, cov_mne.nfree)
      assert_snr(cov.data, cov_mne.data, 1e6)
  
      # test equivalence with np.cov
      cov_np = np.cov(raw.copy().pick(cov["names"]).get_data(), ddof=1)
      if method != "shrunk":  # can check all
          off_diag = np.triu_indices(cov_np.shape[0])
      else:
          # We explicitly zero out off-diag entries between channel types,
          # so let's just check MEG off-diag entries
          off_diag = np.triu_indices(
              len(pick_types(raw.info, meg=True, exclude=()))
          )
      for other in (cov_mne, cov):
          assert_allclose(
              np.diag(cov_np), np.diag(other.data), rtol=5e-6
          )
          assert_allclose(
              cov_np[off_diag], other.data[off_diag], rtol=4e-3
          )
          assert_snr(cov.data, other.data, 1e6)
  
      # tstep=0.2 (default)
      with _record_warnings():  # can warn about EEG ref
          cov = compute_raw_covariance(
              raw,
              method=method,
              rank="full",
              method_params=method_params,
          )
      assert_equal(
          cov.nfree, cov_mne.nfree - 120
      )  # cutoff some samples
      assert_snr(cov.data, cov_mne.data, 170)
  
      # test IO when computation done in Python
      cov.save(tmp_path / "test-cov.fif")  # test saving
      cov_read = read_cov(tmp_path / "test-cov.fif")
      assert cov_read.ch_names == cov.ch_names
      assert cov_read.nfree == cov.nfree
      assert_array_almost_equal(cov.data, cov_read.data)
  
      # test with a subset of channels
      raw_pick = raw.copy().pick(raw.ch_names[:5])
      raw_pick.info.normalize_proj()
      cov = compute_raw_covariance(
          raw_pick,
          tstep=None,
          method=method,
          rank="full",
          method_params=method_params,
      )
      assert cov_mne.ch_names[:5] == cov.ch_names
      assert_snr(cov.data, cov_mne.data[:5, :5], 5e6)
      cov = compute_raw_covariance(
          raw_pick,
          method=method,
          rank="full",
          method_params=method_params,
      )
      assert_snr(cov.data, cov_mne.data[:5, :5], 90)  # cutoff samps
      # make sure we get a warning with too short a segment
      raw_2 = read_raw_fif(raw_fname).crop(0, 1)
      with pytest.warns(RuntimeWarning, match="Too few samples"):
          cov = compute_raw_covariance(
              raw_2, method=method, method_params=method_params
          )
      # no epochs found due to rejection
      pytest.raises(
          ValueError,
          compute_raw_covariance,
          raw,
          tstep=None,
          method="empirical",
          reject=dict(eog=200e-6),
      )
      # but this should work
      with _record_warnings():  # sklearn
          cov = compute_raw_covariance(
              raw.copy().crop(0, 10.0),
              tstep=None,
              method=method,
              reject=dict(eog=1000e-6),
              method_params=method_params,
              verbose="error",
          )
  
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 7 for calling a global function with example usage: test_cov_estimation_on_raw(method, tmp_path) without return types