"""The vendored protocol and the packaging around it. The whole point of slice D is that coordinates are *output-local*, and the only thing that makes them so is ``create_virtual_pointer_with_output``, which exists at version 2 of ``zwlr_virtual_pointer_manager_v1`` and not at version 1. So the version is asserted here, cheaply, on the generated source — a regeneration against an older XML would otherwise be a silent downgrade of the one guarantee the slice exists to provide. The pywayland import is checked when pywayland is present and skipped when it is not: the dev shell has no pywayland, the built package does, and this file is run in both. """ from __future__ import annotations import importlib.util from pathlib import Path import pytest HAVE_PYWAYLAND = importlib.util.find_spec("pywayland") is not None # Located through the import system, not through a path relative to this file, # so the suite is the same whether it runs in a checkout or against the # installed package in a build sandbox. _spec = importlib.util.find_spec("hhstream_pointer") assert _spec is not None and _spec.origin, "hhstream_pointer is not importable" PACKAGE = Path(_spec.origin).parent PROTOCOL_DIR = PACKAGE / "_protocol/wlr_virtual_pointer_unstable_v1" MANAGER = PROTOCOL_DIR / "zwlr_virtual_pointer_manager_v1.py" #: Only present in a checkout; a build sandbox gets the test directory alone. PYPROJECT = Path(__file__).resolve().parents[2] / "pyproject.toml" def test_the_generated_protocol_is_vendored(): assert (PROTOCOL_DIR / "__init__.py").is_file() assert MANAGER.is_file() assert (PROTOCOL_DIR / "zwlr_virtual_pointer_v1.py").is_file() # Every vendored file is scanner output; a hand-edit should be noticed. for path in PROTOCOL_DIR.glob("*.py"): assert path.read_text().startswith("# This file has been autogenerated") def test_the_manager_is_version_2_with_the_output_request(): source = MANAGER.read_text() assert " version = 2\n" in source assert "def create_virtual_pointer_with_output(self, seat" in source assert "output: WlOutput | None" in source def test_the_shim_resolves_the_generated_relative_import(): assert "from ..wayland import WlOutput" in MANAGER.read_text() shim = (PROTOCOL_DIR.parent / "wayland.py").read_text() assert "from pywayland.protocol.wayland import WlOutput, WlSeat" in shim @pytest.mark.skipif(not PYPROJECT.is_file(), reason="not running from a checkout") def test_pyproject_declares_the_entry_point_and_the_dependency(): pyproject = PYPROJECT.read_text() assert 'hhstream-pointer = "hhstream_pointer.__main__:main"' in pyproject assert "pywayland" in pyproject @pytest.mark.skipif( not HAVE_PYWAYLAND, reason="pywayland is not in this environment (it is in the built package)", ) def test_the_protocol_binds_against_the_installed_pywayland(): from hhstream_pointer._protocol.wlr_virtual_pointer_unstable_v1 import ( ZwlrVirtualPointerManagerV1, ZwlrVirtualPointerV1, ) assert ZwlrVirtualPointerManagerV1.version == 2 assert ZwlrVirtualPointerV1.version == 2 assert hasattr( ZwlrVirtualPointerManagerV1.proxy_class, "create_virtual_pointer_with_output" ) @pytest.mark.skipif( not HAVE_PYWAYLAND, reason="pywayland is not in this environment (it is in the built package)", ) def test_the_backend_refuses_a_version_1_manager(): from hhstream_pointer.backend import MANAGER_VERSION, ManagerTooOld assert MANAGER_VERSION == 2 message = str(ManagerTooOld(1)) assert "version 1" in message assert "create_virtual_pointer_with_output" in message assert "Refusing to start" in message