import os import sys import types import unittest from pathlib import Path from unittest.mock import patch ROOT = Path(__file__).resolve().parents[1] SRC = ROOT / "src" if str(SRC) not in sys.path: sys.path.insert(0, str(SRC)) import desktop class _FakeX11Adapter: pass class DesktopTests(unittest.TestCase): def test_get_desktop_adapter_loads_x11_adapter(self): fake_module = types.SimpleNamespace(X11Adapter=_FakeX11Adapter) with patch.dict(sys.modules, {"desktop_x11": fake_module}), patch.dict( os.environ, {"XDG_SESSION_TYPE": "x11"}, clear=True, ): adapter = desktop.get_desktop_adapter() self.assertIsInstance(adapter, _FakeX11Adapter) def test_get_desktop_adapter_rejects_wayland_session(self): with patch.dict(os.environ, {"XDG_SESSION_TYPE": "wayland"}, clear=True): with self.assertRaises(SystemExit) as ctx: desktop.get_desktop_adapter() self.assertIn("Wayland is not supported yet", str(ctx.exception)) if __name__ == "__main__": unittest.main()