code: def test_theme_colors(pg_backend, theme, monkeypatch, tmp_path):
      """Test that theme colors propagate properly."""
      darkdetect = pytest.importorskip("darkdetect")
      monkeypatch.setenv("_MNE_FAKE_HOME_DIR", str(tmp_path))
      monkeypatch.delenv("MNE_BROWSER_THEME", raising=False)
      # make it seem like the system is always in light mode
      monkeypatch.setattr(darkdetect, "theme", lambda: "light")
      raw = RawArray(np.zeros((1, 1000)), create_info(1, 1000.0, "eeg"))
      _, api = _check_qt_version(return_api=True)
      if api in ("PyQt6", "PySide6"):
          if (
              theme == "dark"
          ):  # we force darkdetect to say the sys is light
              ctx = pytest.warns(
                  RuntimeWarning, match="not yet supported"
              )
          else:
              ctx = nullcontext()
          return_early = True
      else:
          ctx = nullcontext()
          return_early = False
      with ctx:
          fig = raw.plot(theme=theme)
      if return_early:
          return  # we could add a ton of conditionals below, but KISS
      is_dark = _qt_is_dark(fig)
      # on Darwin these checks get complicated, so don't bother for now
      if platform.system() == "Darwin":
          pytest.skip("Problems on macOS")
      if theme == "dark":
          assert is_dark, theme
      elif theme == "light":
          assert not is_dark, theme
  
      def assert_correct_darkness(widget, want_dark):
          __tracebackhide__ = True  # noqa
          # This should work, but it just picks up the parent in the errant case!
          bgcolor = (
              widget.palette()
              .color(widget.backgroundRole())
              .getRgbF()[:3]
          )
          dark = rgb_to_hls(*bgcolor)[1] < 0.5
          assert (
              dark == want_dark
          ), f"{widget} dark={dark} want_dark={want_dark}"
          # ... so we use a more direct test
          colors = _pixmap_to_ndarray(widget.grab())[:, :, :3]
          dark = colors.mean() < 0.5
          assert (
              dark == want_dark
          ), f"{widget} dark={dark} want_dark={want_dark}"
  
      for widget in (fig.mne.toolbar, fig.statusBar()):
          assert_correct_darkness(widget, is_dark)
  
file_path: mne-python/mne/viz/backends/tests/test_utils.py
imports: import platform
  from colorsys import rgb_to_hls
  from contextlib import nullcontext
  import numpy
  import pytest
  from mne import create_info
  from mne.io import RawArray
  from mne.utils import _check_qt_version
  from mne.viz.backends._utils import _check_color, _get_colormap_from_array, _pixmap_to_ndarray, _qt_is_dark
label_desc: Use image node_id 3 for calling a global function with example usage: test_theme_colors(pg_backend, theme, monkeypatch, tmp_path) without return types