code: def test_apply_inverse_cov(method, pick_ori):
      """Test MNE with precomputed inverse operator on cov."""
      raw = read_raw_fif(fname_raw, preload=True)
      # use 10 s of data
      raw.crop(0, 10)
  
      raw.filter(1, None)
      label_lh = read_label(Path(str(fname_label) % "Aud-lh"))
  
      # test with a free ori inverse
      inverse_operator = read_inverse_operator(fname_inv)
  
      data_cov = compute_raw_covariance(raw, tstep=None)
  
      with pytest.raises(ValueError, match="has not been prepared"):
          apply_inverse_cov(
              data_cov,
              raw.info,
              inverse_operator,
              lambda2=lambda2,
              prepared=True,
          )
  
      this_inv_op = prepare_inverse_operator(
          inverse_operator, nave=1, lambda2=lambda2, method=method
      )
  
      raw_ori = "normal" if pick_ori == "normal" else "vector"
      stc_raw = apply_inverse_raw(
          raw,
          this_inv_op,
          lambda2,
          method,
          label=label_lh,
          nave=1,
          pick_ori=raw_ori,
          prepared=True,
      )
      stc_cov = apply_inverse_cov(
          data_cov,
          raw.info,
          this_inv_op,
          method=method,
          pick_ori=pick_ori,
          label=label_lh,
          prepared=True,
          lambda2=lambda2,
      )
      n_sources = np.prod(stc_cov.data.shape[:-1])
      raw_data = stc_raw.data.reshape(n_sources, -1)
      exp_res = np.diag(np.cov(raw_data, ddof=1)).copy()
      exp_res *= 1 if raw_ori == pick_ori else 3.0
      # There seems to be some precision penalty when combining orientations,
      # but it's probably acceptable
      rtol = 5e-4 if pick_ori is None else 1e-12
      assert_allclose(exp_res, stc_cov.data.ravel(), rtol=rtol)
  
      with pytest.raises(ValueError, match="Invalid value"):
          apply_inverse_cov(
              data_cov,
              raw.info,
              this_inv_op,
              method=method,
              pick_ori="vector",
          )
  
imports: import copy
  import re
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from scipy import sparse
  import mne
  from mne import Covariance, EvokedArray, SourceEstimate, combine_evoked, compute_raw_covariance, convert_forward_solution, make_ad_hoc_cov, make_forward_solution, make_sphere_model, pick_channels_forward, pick_types, pick_types_forward, read_cov, read_evokeds, read_forward_solution
  from mne.datasets import testing
  from mne.epochs import Epochs, EpochsArray, make_fixed_length_epochs
  from mne.event import read_events
  from mne.forward import apply_forward, is_fixed_orient, restrict_forward_to_stc
  from mne.io import read_info, read_raw_fif
  from mne.label import label_sign_flip, read_label
  from mne.minimum_norm import INVERSE_METHODS, apply_inverse, apply_inverse_cov, apply_inverse_epochs, apply_inverse_raw, apply_inverse_tfr_epochs, compute_rank_inverse, make_inverse_operator, prepare_inverse_operator, read_inverse_operator, write_inverse_operator
  from mne.source_estimate import VolSourceEstimate, read_source_estimate
  from mne.source_space._source_space import _get_src_nn
  from mne.surface import _normal_orth
  from mne.time_frequency import EpochsTFR
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 27 for calling a global function with example usage: test_apply_inverse_cov(method, pick_ori) without return types