Skip to content

Commit 0dfdc5f

Browse files
authored
testing: adding a test for getting a tree with two outputs (#309)
1 parent a38a0e5 commit 0dfdc5f

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

tests/ipc/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ pip install -r requirements.txt
1515
source venv/bin/activate
1616
pytest
1717
```
18+
19+
### Environment variables
20+
- `MIRACLE_IPC_TEST_USE_ENV`: If set to true, tests will use the local environment to test
21+
miracle-wm against instead of spawning miracle-wm itself.
22+
- `MIRACLE_IPC_TEST_BIN`: can be set to a `path/to/miracle-wm`. Defaults to `miracle-wm`.

tests/ipc/conftest.py

+40-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess
33
from subprocess import Popen, PIPE, STDOUT
44
import os
5+
from typing import List, Tuple, Dict
56

67
class Server:
78
def __init__(self, ipc: str, wayland: str) -> None:
@@ -12,22 +13,54 @@ def open_app(self, command: str):
1213
my_env = os.environ.copy()
1314
my_env['WAYLAND_DISPLAY'] = self.wayland
1415
return subprocess.Popen([command], env=my_env)
16+
17+
def _create_server(args: List[str]) -> Tuple[Popen[bytes], Dict[str, str]]:
18+
command = "miracle-wm"
19+
if "MIRACLE_IPC_TEST_BIN" in os.environ:
20+
command = os.environ["MIRACLE_IPC_TEST_BIN"]
21+
22+
env = os.environ.copy()
23+
env['WAYLAND_DISPLAY'] = 'wayland-98'
24+
process = Popen([command] + args,
25+
env=env, stdout=PIPE, stderr=STDOUT)
26+
return (process, env)
1527

1628
@pytest.fixture(scope="function")
1729
def server():
1830
if "MIRACLE_IPC_TEST_USE_ENV" in os.environ:
1931
yield Server(os.environ["SWAYSOCK"], os.environ["WAYLAND_DISPLAY"])
2032
return
2133

22-
command = "miracle-wm"
23-
if "MIRACLE_IPC_TEST_BIN" in os.environ:
24-
command = os.environ["MIRACLE_IPC_TEST_BIN"]
34+
(process, env) = _create_server(['--platform-display-libs', 'mir:virtual', '--virtual-output', '800x600', '--no-config', '1'])
35+
socket = ""
36+
to_find = "Listening to IPC socket on path: "
37+
with process.stdout:
38+
for line in iter(process.stdout.readline, b''):
39+
data = line.decode("utf-8").strip()
40+
# print(data)
41+
if to_find in data:
42+
i = data.index(to_find)
43+
i = i + len(to_find)
44+
socket = data[i:].strip()
45+
break
46+
47+
yield Server(socket, env["WAYLAND_DISPLAY"])
48+
49+
# for line in iter(process.stdout.readline, b''):
50+
# data = line.decode("utf-8").strip()
51+
# print(data)
52+
53+
process.terminate()
54+
return
2555

26-
env = os.environ.copy()
27-
env['WAYLAND_DISPLAY'] = 'wayland-98'
28-
process = Popen([command, '--platform-display-libs', 'mir:virtual', '--virtual-output', '800x600', '--no-config', '1'],
29-
env=env, stdout=PIPE, stderr=STDOUT)
56+
57+
@pytest.fixture(scope="function")
58+
def multi_win_server():
59+
if "MIRACLE_IPC_TEST_USE_ENV" in os.environ:
60+
yield Server(os.environ["SWAYSOCK"], os.environ["WAYLAND_DISPLAY"])
61+
return
3062

63+
(process, env) = _create_server(['--platform-display-libs', 'mir:virtual', '--virtual-output', '800x600', '--virtual-output', '400x300', '--no-config', '1'])
3164
socket = ""
3265
to_find = "Listening to IPC socket on path: "
3366
with process.stdout:

tests/ipc/test_get_tree.py

+5
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ def test_percent_two_containers(self, server):
5252
app = workspace.nodes[1]
5353
assert app.focused == True
5454
assert app.percent == 0.5
55+
56+
def test_two_outputs(self, multi_win_server):
57+
conn = Connection(multi_win_server.ipc)
58+
container = conn.get_tree()
59+
assert len(container.nodes) == 2

0 commit comments

Comments
 (0)