code: def test_plot_ica_sources(raw_orig, browser_backend, monkeypatch):
      """Test plotting of ICA panel."""
      raw = raw_orig.copy().crop(0, 1)
      picks = _get_picks(raw)
      epochs = _get_epochs()
      raw.pick([raw.ch_names[k] for k in picks])
      ica_picks = pick_types(
          raw.info,
          meg=True,
          eeg=False,
          stim=False,
          ecg=False,
          eog=False,
          exclude="bads",
      )
      ica = ICA(n_components=2)
      ica.fit(raw, picks=ica_picks)
      ica.exclude = [1]
      if sys.platform == "darwin":  # unknown transformation bug
          monkeypatch.setenv("MNE_BROWSE_RAW_SIZE", "20,20")
      fig = ica.plot_sources(raw)
      assert browser_backend._get_n_figs() == 1
      # change which component is in ICA.exclude (click data trace to remove
      # current one; click name to add other one)
      fig._redraw()
      assert_array_equal(ica.exclude, [1])
      assert fig.mne.info["bads"] == [ica._ica_names[1]]
      x = fig.mne.traces[1].get_xdata()[5]
      y = fig.mne.traces[1].get_ydata()[5]
      fig._fake_click((x, y), xform="data")  # exclude = []
      assert fig.mne.info["bads"] == []
      assert_array_equal(ica.exclude, [1])  # unchanged
      fig._click_ch_name(ch_index=0, button=1)  # exclude = [0]
      assert fig.mne.info["bads"] == [ica._ica_names[0]]
      assert_array_equal(ica.exclude, [1])
      fig._fake_keypress(fig.mne.close_key)
      fig._close_event()
      assert browser_backend._get_n_figs() == 0
      assert_array_equal(ica.exclude, [0])
      # test when picks does not include ica.exclude.
      ica.plot_sources(raw, picks=[1])
      assert browser_backend._get_n_figs() == 1
      browser_backend._close_all()
  
      # dtype can change int->np.int64 after load, test it explicitly
      ica.n_components_ = np.int64(ica.n_components_)
  
      # test clicks on y-label (need >2 secs for plot_properties() to work)
      long_raw = raw_orig.crop(0, 5)
      fig = ica.plot_sources(long_raw)
      assert browser_backend._get_n_figs() == 1
      fig._redraw()
      fig._click_ch_name(ch_index=0, button=3)
      assert len(fig.mne.child_figs) == 1
      assert browser_backend._get_n_figs() == 2
      # close child fig directly (workaround for mpl issue #18609)
      fig._fake_keypress("escape", fig=fig.mne.child_figs[0])
      assert browser_backend._get_n_figs() == 1
      fig._fake_keypress(fig.mne.close_key)
      assert browser_backend._get_n_figs() == 0
      del long_raw
  
      # test with annotations and a measurement date
      orig_annot = raw.annotations
      raw.set_annotations(Annotations([0.2], [0.1], "Test"))
      fig = ica.plot_sources(raw)
      if browser_backend.name == "matplotlib":
          assert len(fig.mne.ax_main.collections) == 1
          assert len(fig.mne.ax_hscroll.collections) == 1
      else:
          assert len(fig.mne.regions) == 1
          assert_allclose(fig.mne.regions[0].getRegion(), (0.2, 0.3))
  
      # test with annotations and no measurement date
      orig_meas_date = raw.info["meas_date"]
      raw.set_meas_date(None)
      assert raw.first_samp != 0
      raw.set_annotations(Annotations([0.2], [0.1], "Test"))
      fig = ica.plot_sources(raw)
      if browser_backend.name == "matplotlib":
          assert len(fig.mne.ax_main.collections) == 1
          assert len(fig.mne.ax_hscroll.collections) == 1
      else:
          assert len(fig.mne.regions) == 1
          assert_allclose(fig.mne.regions[0].getRegion(), (0.2, 0.3))
  
      raw.set_meas_date(orig_meas_date)
      raw.set_annotations(orig_annot)
  
      # test error handling
      raw_ = raw.copy().load_data()
      raw_.drop_channels("MEG 0113")
      with pytest.raises(ValueError, match="could not be picked"):
          ica.plot_sources(inst=raw_)
      epochs_ = epochs.copy().load_data()
      epochs_.drop_channels("MEG 0113")
      with pytest.raises(ValueError, match="could not be picked"):
          ica.plot_sources(inst=epochs_)
      del raw_
      del epochs_
  
      # test w/ epochs and evokeds
      ica.plot_sources(epochs)
      ica.plot_sources(epochs.average())
      evoked = epochs.average()
      fig = ica.plot_sources(evoked)
      # Test a click
      ax = fig.get_axes()[0]
      line = ax.lines[0]
      _fake_click(
          fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], "data"
      )
      _fake_click(fig, ax, [ax.get_xlim()[0], ax.get_ylim()[1]], "data")
  
      # plot with bad channels excluded
      ica.exclude = [0]
      ica.plot_sources(evoked)
  
      # regression test for `IndexError` when passing non-consecutive picks or consecutive
      # picks not including `0` (https://github.com/mne-tools/mne-python/pull/11808)
      ica.plot_sources(evoked, picks=1)
  
      # pretend find_bads_eog() yielded some results
      ica.labels_ = {"eog": [0], "eog/0/crazy-channel": [0]}
      ica.plot_sources(evoked)  # now with labels
  
      # pass an invalid inst
      with pytest.raises(
          ValueError, match="must be of Raw or Epochs type"
      ):
          ica.plot_sources("meeow")
  
imports: import sys
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from mne import Annotations, Epochs, make_fixed_length_events, pick_types, read_cov, read_events
  from mne.io import read_raw_fif
  from mne.preprocessing import ICA, create_ecg_epochs, create_eog_epochs
  from mne.utils import _record_warnings, catch_logging
  from mne.viz.ica import _create_properties_layout, plot_ica_properties
  from mne.viz.utils import _fake_click, _fake_keypress
label_desc: Use image node_id 7 for calling a global function with example usage: test_plot_ica_sources(raw_orig, browser_backend, monkeypatch) without return types