code: def test_events(app, status, warning):
      def empty():
          pass
  
      with pytest.raises(ExtensionError) as excinfo:
          app.connect("invalid", empty)
      assert "Unknown event name: invalid" in str(excinfo.value)
  
      app.add_event("my_event")
      with pytest.raises(ExtensionError) as excinfo:
          app.add_event("my_event")
      assert "Event 'my_event' already present" in str(excinfo.value)
  
      def mock_callback(a_app, *args):
          assert a_app is app
          assert emit_args == args
          return "ret"
  
      emit_args = (1, 3, "string")
      listener_id = app.connect("my_event", mock_callback)
      assert app.emit("my_event", *emit_args) == [
          "ret"
      ], "Callback not called"
  
      app.disconnect(listener_id)
      assert (
          app.emit("my_event", *emit_args) == []
      ), "Callback called when disconnected"
  
file_path: sphinx/tests/test_application.py
imports: import shutil
  import sys
  from io import StringIO
  from pathlib import Path
  from unittest.mock import Mock
  import pytest
  from docutils import nodes
  import sphinx.application
  from sphinx.errors import ExtensionError
  from sphinx.testing.util import SphinxTestApp, strip_escseq
  from sphinx.util import logging
label_desc: Use image node_id 2 for calling a global function with example usage: test_events(app, status, warning) and returns: str