code: def test_unsubscribe(event_channels):
      """Test unsubscribing from UI events."""
      callback1_calls = list()
      callback2_calls = list()
  
      def callback1(event):
          """Respond to time change event."""
          callback1_calls.append(event)
  
      def callback2(event):
          """Respond to time change event."""
          callback2_calls.append(event)
  
      fig = plt.figure()
  
      def setup_events():
          """Reset UI event scenario."""
          callback1_calls.clear()
          callback2_calls.clear()
          ui_events.unsubscribe(fig, "all")
          ui_events.subscribe(fig, "figure_closing", callback1)
          ui_events.subscribe(fig, "time_change", callback1)
          ui_events.subscribe(fig, "time_change", callback2)
  
      # Test unsubscribing from a single event
      setup_events()
      with pytest.warns(RuntimeWarning, match="Cannot unsubscribe"):
          ui_events.unsubscribe(fig, "nonexisting_event")
      ui_events.unsubscribe(fig, "time_change")
      assert "time_change" not in ui_events._get_event_channel(fig)
      assert "figure_closing" in ui_events._get_event_channel(fig)
      ui_events.publish(fig, ui_events.TimeChange(time=10.2))
      assert not callback1_calls
      assert not callback2_calls
      ui_events.publish(fig, ui_events.FigureClosing())
      assert callback1_calls
  
      # Test unsubscribing from all events
      setup_events()
      ui_events.unsubscribe(fig, "all")
      assert "time_change" not in ui_events._get_event_channel(fig)
      assert "figure_closing" not in ui_events._get_event_channel(fig)
      ui_events.publish(fig, ui_events.TimeChange(time=10.2))
      ui_events.publish(fig, ui_events.FigureClosing())
      assert not callback1_calls
      assert not callback2_calls
  
      # Test unsubscribing from a list of events
      setup_events()
      ui_events.unsubscribe(fig, ["time_change", "figure_closing"])
      assert "time_change" not in ui_events._get_event_channel(fig)
      assert "figure_closing" not in ui_events._get_event_channel(fig)
      ui_events.publish(fig, ui_events.TimeChange(time=10.2))
      ui_events.publish(fig, ui_events.FigureClosing())
      assert not callback1_calls
      assert not callback2_calls
  
      # Test unsubscribing a specific callback function from a single event
      setup_events()
      with pytest.warns(RuntimeWarning, match="Cannot unsubscribe"):
          ui_events.unsubscribe(fig, "figure_closing", callback2)
      ui_events.unsubscribe(fig, "time_change", callback2)
      ui_events.publish(fig, ui_events.TimeChange(time=10.2))
      assert callback1_calls
      assert not callback2_calls
  
      # Test unsubscribing a specific callback function from all events
      setup_events()
      ui_events.unsubscribe(fig, "all", callback2)
      ui_events.publish(fig, ui_events.TimeChange(time=10.2))
      assert callback1_calls
      assert not callback2_calls
  
      # Test unsubscribing a specific callback function from a list of events
      setup_events()
      ui_events.unsubscribe(
          fig, ["time_change", "figure_closing"], callback1
      )
      ui_events.publish(fig, ui_events.TimeChange(time=10.2))
      ui_events.publish(fig, ui_events.FigureClosing())
      assert not callback1_calls
  
file_path: mne-python/mne/viz/tests/test_ui_events.py
imports: import matplotlib.pyplot
  import pytest
  from mne.datasets import testing
  from mne.viz import ui_events
label_desc: Use image node_id 7 for calling a global function with example usage: test_unsubscribe(event_channels) without return types