diff --git a/tests/ipc/README.md b/tests/ipc/README.md index 73ce3c14..a7508dad 100644 --- a/tests/ipc/README.md +++ b/tests/ipc/README.md @@ -15,3 +15,8 @@ pip install -r requirements.txt source venv/bin/activate pytest ``` + +### Environment variables +- `MIRACLE_IPC_TEST_USE_ENV`: If set to true, tests will use the local environment to test + miracle-wm against instead of spawning miracle-wm itself. +- `MIRACLE_IPC_TEST_BIN`: can be set to a `path/to/miracle-wm`. Defaults to `miracle-wm`. \ No newline at end of file diff --git a/tests/ipc/conftest.py b/tests/ipc/conftest.py index b5ec67d6..bb2227e9 100644 --- a/tests/ipc/conftest.py +++ b/tests/ipc/conftest.py @@ -2,6 +2,7 @@ import subprocess from subprocess import Popen, PIPE, STDOUT import os +from typing import List, Tuple, Dict class Server: def __init__(self, ipc: str, wayland: str) -> None: @@ -12,6 +13,17 @@ def open_app(self, command: str): my_env = os.environ.copy() my_env['WAYLAND_DISPLAY'] = self.wayland return subprocess.Popen([command], env=my_env) + +def _create_server(args: List[str]) -> Tuple[Popen[bytes], Dict[str, str]]: + command = "miracle-wm" + if "MIRACLE_IPC_TEST_BIN" in os.environ: + command = os.environ["MIRACLE_IPC_TEST_BIN"] + + env = os.environ.copy() + env['WAYLAND_DISPLAY'] = 'wayland-98' + process = Popen([command] + args, + env=env, stdout=PIPE, stderr=STDOUT) + return (process, env) @pytest.fixture(scope="function") def server(): @@ -19,15 +31,36 @@ def server(): yield Server(os.environ["SWAYSOCK"], os.environ["WAYLAND_DISPLAY"]) return - command = "miracle-wm" - if "MIRACLE_IPC_TEST_BIN" in os.environ: - command = os.environ["MIRACLE_IPC_TEST_BIN"] + (process, env) = _create_server(['--platform-display-libs', 'mir:virtual', '--virtual-output', '800x600', '--no-config', '1']) + socket = "" + to_find = "Listening to IPC socket on path: " + with process.stdout: + for line in iter(process.stdout.readline, b''): + data = line.decode("utf-8").strip() + # print(data) + if to_find in data: + i = data.index(to_find) + i = i + len(to_find) + socket = data[i:].strip() + break + + yield Server(socket, env["WAYLAND_DISPLAY"]) + + # for line in iter(process.stdout.readline, b''): + # data = line.decode("utf-8").strip() + # print(data) + + process.terminate() + return - env = os.environ.copy() - env['WAYLAND_DISPLAY'] = 'wayland-98' - process = Popen([command, '--platform-display-libs', 'mir:virtual', '--virtual-output', '800x600', '--no-config', '1'], - env=env, stdout=PIPE, stderr=STDOUT) + +@pytest.fixture(scope="function") +def multi_win_server(): + if "MIRACLE_IPC_TEST_USE_ENV" in os.environ: + yield Server(os.environ["SWAYSOCK"], os.environ["WAYLAND_DISPLAY"]) + return + (process, env) = _create_server(['--platform-display-libs', 'mir:virtual', '--virtual-output', '800x600', '--virtual-output', '400x300', '--no-config', '1']) socket = "" to_find = "Listening to IPC socket on path: " with process.stdout: diff --git a/tests/ipc/test_get_tree.py b/tests/ipc/test_get_tree.py index 936f0220..1253bfbf 100644 --- a/tests/ipc/test_get_tree.py +++ b/tests/ipc/test_get_tree.py @@ -52,3 +52,8 @@ def test_percent_two_containers(self, server): app = workspace.nodes[1] assert app.focused == True assert app.percent == 0.5 + + def test_two_outputs(self, multi_win_server): + conn = Connection(multi_win_server.ipc) + container = conn.get_tree() + assert len(container.nodes) == 2