mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 22:01:22 +01:00
feat(nix): KDE as a Platform, and the tiling scenario in core-e2e
KdePlatform is a Kde session seen through the neutral vocabulary: kdotool for the OS's frames, foot for clients, the cell of its font as the tolerance. The core-e2e suite runs scenarios.tiling through it as a new section, so that the scenario that will run on Windows is checked on the one platform that works; the suite's own sections are unchanged. It passes on KVM (74 checks) on the WSL2 machine.
This commit is contained in:
1 parent
2c5e8f57dc
commit
bb8299410f
4 files changed
+80
-3
No files matched your search
@@ -149,6 +149,14 @@ the run.
|
||||
goes in `Snapshot.extra`. Its unit tests use fixtures written from the two
|
||||
ports' serializers; recorded states replace them once a run on each port
|
||||
exists.
|
||||
- `Platform` (`core/platform.py`) is what a scenario needs of a platform: start the
|
||||
daemon, run `komorebic`, read the `Snapshot`, open a window, ask the operating
|
||||
system for its frame (`os_window`, the oracle: the daemon's state is the thing
|
||||
under test), and take a screenshot. `core/scenarios` has the scenarios written
|
||||
against it; `tiling` is the first. A method is added with the first scenario
|
||||
that needs it. `KdePlatform` (`kde_platform.py`) is a `Kde` session as a
|
||||
`Platform`, and the `core-e2e` suite runs `tiling` through it after its own
|
||||
sections.
|
||||
- `Checks` counts checks and fails once, at the end, so that one failure does
|
||||
not hide the ones after it. `finish()` prints `passed: N failed: M`, and its
|
||||
error names the checks that failed, which `nix build` shows in the last lines
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"""KDE as a [`Platform`](komorebi_vm.core.platform.Platform): a `Kde` session, seen through the
|
||||
neutral vocabulary."""
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from komorebi_vm.core import snapshot
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow, Predicate
|
||||
from komorebi_vm.core.snapshot import Snapshot
|
||||
from komorebi_vm.kde import Kde
|
||||
|
||||
# foot sizes itself to whole cells of its font, so its frame can be short of the one asked for
|
||||
CELL = 24
|
||||
|
||||
|
||||
class KdePlatform:
|
||||
"""The platform of a headless KWin session of the test machine."""
|
||||
|
||||
def __init__(self, kde: Kde, size: tuple[int, int]) -> None:
|
||||
self.kde = kde
|
||||
self.size = size
|
||||
|
||||
@property
|
||||
def tolerance(self) -> int:
|
||||
return CELL
|
||||
|
||||
def wait_for(self, predicate: Predicate, timeout: float = 10) -> bool:
|
||||
return self.kde.wait_for(predicate, timeout=timeout)
|
||||
|
||||
def start_komorebi(self) -> None:
|
||||
self.kde.start_komorebi()
|
||||
status = self.kde.wait_for(lambda: self.kde.run("komorebic state")[0] == 0, timeout=30)
|
||||
if not status:
|
||||
raise AssertionError("the daemon did not answer komorebic")
|
||||
|
||||
def komorebic(self, *args: str) -> str:
|
||||
return self.kde.komorebic(*args)
|
||||
|
||||
def state(self) -> Snapshot:
|
||||
return snapshot.parse(self.kde.state())
|
||||
|
||||
def spawn(self, title: str) -> Client:
|
||||
self.kde.spawn(f"foot -T {title} sleep 3000")
|
||||
self.kde.wait_for(lambda: self.kde.wid(title) != "", timeout=30)
|
||||
return Client(title)
|
||||
|
||||
def os_window(self, client: Client) -> OsWindow | None:
|
||||
wid = self.kde.wid(client.title)
|
||||
if wid == "":
|
||||
return None
|
||||
return OsWindow(client.title, self.kde.rect(wid), self.kde.active() == wid)
|
||||
|
||||
def work_area(self) -> Rect:
|
||||
return Rect(0, 0, *self.size)
|
||||
|
||||
def activate(self, client: Client) -> None:
|
||||
self.kde.activate(self.kde.wid(client.title))
|
||||
|
||||
def screenshot(self, name: str) -> Image.Image:
|
||||
return self.kde.shot(name)
|
||||
@@ -10,7 +10,7 @@ requires-python = ">=3.12"
|
||||
dependencies = ["pillow"]
|
||||
|
||||
[tool.setuptools]
|
||||
packages = ["komorebi_vm", "komorebi_vm.core"]
|
||||
packages = ["komorebi_vm", "komorebi_vm.core", "komorebi_vm.core.scenarios"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
komorebi_vm = ["py.typed"]
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
import json
|
||||
|
||||
from komorebi_vm import Checks, Kde, Rect, daemon
|
||||
from komorebi_vm.core.scenarios import tiling
|
||||
from komorebi_vm.kde_platform import KdePlatform
|
||||
|
||||
W, H = 1920, 1080
|
||||
PARK = "komorebi-park"
|
||||
@@ -346,12 +348,19 @@ checks.check(
|
||||
)
|
||||
report(["afterwards"])
|
||||
|
||||
print("== 12. komorebic stop")
|
||||
print("== 12. the same tiling, through the neutral platform")
|
||||
# the scenario of komorebi_vm.core.scenarios.tiling is what runs on Windows too: it asks the
|
||||
# operating system where the windows are, and not the daemon's log
|
||||
kde.close(kde.wid("afterwards"))
|
||||
checks.check("the window of the last section is closed", kde.wait_for(lambda: kde.managed() == 0))
|
||||
tiling.run(KdePlatform(kde, (W, H)), checks, titles=("neutral1", "neutral2", "neutral3"))
|
||||
|
||||
print("== 13. komorebic stop")
|
||||
kde.komorebic("stop")
|
||||
checks.check("the daemon exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
checks.check("its socket is gone", kde.run(f"test -e {kde.runtime}/komorebi/komorebi.sock")[0] != 0)
|
||||
checks.check("the script is no longer in KWin", kde.wait_for(lambda: not kde.script_loaded()))
|
||||
checks.check("the window stays", kde.wid("afterwards") != "")
|
||||
checks.check("the windows stay", kde.wid("neutral1") != "")
|
||||
|
||||
kde.stop()
|
||||
checks.finish()
|
||||
Reference in new issue
Block a user