2
2
import subprocess
3
3
from subprocess import Popen , PIPE , STDOUT
4
4
import os
5
+ from typing import List , Tuple , Dict
5
6
6
7
class Server :
7
8
def __init__ (self , ipc : str , wayland : str ) -> None :
@@ -12,22 +13,54 @@ def open_app(self, command: str):
12
13
my_env = os .environ .copy ()
13
14
my_env ['WAYLAND_DISPLAY' ] = self .wayland
14
15
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 )
15
27
16
28
@pytest .fixture (scope = "function" )
17
29
def server ():
18
30
if "MIRACLE_IPC_TEST_USE_ENV" in os .environ :
19
31
yield Server (os .environ ["SWAYSOCK" ], os .environ ["WAYLAND_DISPLAY" ])
20
32
return
21
33
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
25
55
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
30
62
63
+ (process , env ) = _create_server (['--platform-display-libs' , 'mir:virtual' , '--virtual-output' , '800x600' , '--virtual-output' , '400x300' , '--no-config' , '1' ])
31
64
socket = ""
32
65
to_find = "Listening to IPC socket on path: "
33
66
with process .stdout :
0 commit comments