Skip to content

Commit

Permalink
testing: adding a test for getting a tree with two outputs (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae authored Nov 29, 2024
1 parent a38a0e5 commit 0dfdc5f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
5 changes: 5 additions & 0 deletions tests/ipc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
47 changes: 40 additions & 7 deletions tests/ipc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -12,22 +13,54 @@ 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():
if "MIRACLE_IPC_TEST_USE_ENV" in os.environ:
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:
Expand Down
5 changes: 5 additions & 0 deletions tests/ipc/test_get_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0dfdc5f

Please sign in to comment.