code: def test_ica_core(
      method, n_components, noise_cov, n_pca_components, browser_backend
  ):
      """Test ICA on raw and epochs."""
      _skip_check_picard(method)
      raw = read_raw_fif(raw_fname).crop(0, stop).load_data()
  
      # The None cases help reveal bugs but are time consuming.
      if noise_cov:
          noise_cov = read_cov(test_cov_name)
          noise_cov["projs"] = []  # avoid warnings
      else:
          noise_cov = None
      events = read_events(event_name)
      picks = pick_types(
          raw.info,
          meg=True,
          stim=False,
          ecg=False,
          eog=False,
          exclude="bads",
      )[::4]
      raw.pick(picks[::4])
      raw.del_proj()
      del picks
      epochs = Epochs(
          raw,
          events[:4],
          event_id,
          tmin,
          tmax,
          baseline=None,
          preload=True,
      )
  
      # test essential core functionality
  
      # Test ICA raw
      ica = ICA(
          noise_cov=noise_cov,
          n_components=n_components,
          method=method,
          max_iter=1,
      )
      with pytest.raises(
          ValueError, match="Cannot check for channels of t"
      ):
          "meg" in ica
  
      print(ica)  # to test repr
      repr_ = ica.__repr__()
      repr_html_ = ica._repr_html_()
      assert repr_ == f"<ICA | no decomposition, method: {method}>"
      assert method in repr_html_
      assert "max_iter=1" in repr_html_
  
      # test fit checker
      with pytest.raises(RuntimeError, match="No fit available"):
          ica.get_sources(raw)
      with pytest.raises(RuntimeError, match="No fit available"):
          ica.get_sources(epochs)
  
      # Test error upon empty epochs fitting
      with pytest.raises(RuntimeError, match="none were found"):
          ica.fit(epochs[0:0])
  
      # test decomposition
      with pytest.warns(UserWarning, match="did not converge"):
          ica.fit(raw)
      repr(ica)  # to test repr
      repr_ = ica.__repr__()
      repr_html_ = ica._repr_html_()
      assert "raw data decomposition" in repr_
      assert f"{ica.n_components_} ICA components" in repr_
      assert "Available PCA components" in repr_html_
      assert "mag" in ica  # should now work without error
  
      # test re-fit
      unmixing1 = ica.unmixing_matrix_
      with pytest.warns(UserWarning, match="did not converge"):
          ica.fit(raw)
      assert_array_almost_equal(unmixing1, ica.unmixing_matrix_)
  
      raw_sources = ica.get_sources(raw)
      # test for #3804
      assert_equal(raw_sources._filenames, [None])
      print(raw_sources)
  
      # test for gh-6271 (scaling of ICA traces)
      fig = raw_sources.plot(clipping=None)
      assert len(fig.mne.traces) in (2, 6)
      for line in fig.mne.traces:
          y = line.get_ydata()
          assert np.ptp(y) < 15
  
      sources = raw_sources[:, :][0]
      assert sources.shape[0] == ica.n_components_
  
      # test preload filter
      raw3 = raw.copy()
      raw3.preload = False
      with pytest.raises(RuntimeError, match="to be loaded"):
          ica.apply(raw3)
  
      #######################################################################
      # test epochs decomposition
      ica = ICA(
          noise_cov=noise_cov, n_components=n_components, method=method
      )
      with _record_warnings():  # sometimes warns
          ica.fit(epochs)
      _assert_ica_attributes(
          ica, epochs.get_data(copy=False), limits=(0.2, 20)
      )
      data = epochs.get_data(picks=[0])[:, 0]
      n_samples = np.prod(data.shape)
      assert_equal(ica.n_samples_, n_samples)
      print(ica)  # to test repr
  
      sources = ica.get_sources(epochs).get_data(copy=False)
      assert sources.shape[1] == ica.n_components_
  
      with pytest.raises(
          ValueError, match="target do not have the same nu"
      ):
          ica.score_sources(epochs, target=np.arange(1))
  
      # test preload filter
      epochs3 = epochs.copy()
      epochs3.preload = False
      with pytest.raises(
          RuntimeError, match="requires epochs data to be l"
      ):
          ica.apply(epochs3)
  
      # test for bug with whitener updating
      _pre_whitener = ica.pre_whitener_.copy()
      epochs._data[:, 0, 10:15] *= 1e12
      ica.apply(epochs.copy())
      assert_array_equal(_pre_whitener, ica.pre_whitener_)
  
      # test expl. var threshold leading to empty sel
      ica.n_components = 0.1
      with pytest.raises(
          RuntimeError, match="One PCA component captures most"
      ):
          ica.fit(epochs)
  
      offender = (
          1,
          2,
          3,
      )
      with pytest.raises(ValueError, match="Data input must be of Raw"):
          ica.get_sources(offender)
      with pytest.raises(TypeError, match="must be an instance of"):
          ica.fit(offender)
      with pytest.raises(TypeError, match="must be an instance of"):
          ica.apply(offender)
  
      # gh-7868
      ica.n_pca_components = 3
      ica.n_components = None
      with pytest.raises(
          ValueError, match="pca_components.*is greater"
      ):
          ica.fit(epochs, picks=[0, 1])
      ica.n_pca_components = None
      ica.n_components = 3
      with pytest.raises(
          ValueError, match="n_components.*cannot be greater"
      ):
          ica.fit(epochs, picks=[0, 1])
  
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 12 for calling a global function with example usage: test_ica_core(method, n_components, noise_cov, n_pca_components, browser_backend) without return types