Skip to content

Commit 4a4da80

Browse files
committed
Improved logic to wait for GNOME Shell, fixed screenshot path
1 parent be7c9e2 commit 4a4da80

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

tests/features/environment.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _gjs_cmdline(self, code):
2020
SHELL_DBUS = "org.gnome.Shell"
2121
SHELL_OBJECT = "/org/gnome/Shell"
2222
EVAL_DBUS = "org.gnome.Shell.Eval"
23-
code_full = f''' paperwm = Main.extensionManager.lookup("paperwm@paperwm.github.com").stateObj; {code} '''
23+
code_full = f''' let paperwm = Main.extensionManager.lookup("paperwm@paperwm.github.com").stateObj; {code} '''
2424
esc_code = code_full.replace('"', '\\"').replace('`', '\\`')
2525
return f"sudo -u user gdbus call -a unix:path=/run/user/1000/bus -d {SHELL_DBUS} --object-path {SHELL_OBJECT} --method {EVAL_DBUS} \"{esc_code}\""
2626

@@ -32,13 +32,18 @@ def libinput_play(self, recording):
3232

3333
def gjs_eval(self, code):
3434
''' Execute the specified GJS code from within the GNOME Shell process.
35+
Will raise Exception in the event of a GJS error.
3536
'''
36-
return self.machine.succeed(self._gjs_cmdline(code))
37+
result = eval(self.machine.succeed(self._gjs_cmdline(code)))
38+
if result[0]:
39+
return result[1]
40+
else:
41+
raise Exception(result[1])
3742

3843
def wait_for_paperwm(self):
3944
''' Wait until GNOME Shell is able to yield PaperWM internal state.
4045
'''
41-
return self.machine.wait_until_succeeds(self._gjs_cmdline('paperwm.findModule("tiling").spaces._initDone'))
46+
return self.machine.wait_until_succeeds(self._gjs_cmdline('paperwm.findModule("tiling").spaces._initDone') + "| grep \"(true, 'true')\"")
4247

4348
def screenshot(self):
4449
''' Take a screenshot and load it as an OpenCV-compatible representation

tests/features/steps/visual.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
@then("the screen should match {image}")
88
def scrcompare_simple(context, image):
99
screen = context.nixos.screenshot()
10-
template = cv2.imread(Path(context.config.base_dir) / "screenshots" / f"{image}.png")
10+
template = cv2.imread(Path(context.config.base_dir).parent.resolve() / "screenshots" / f"{image}.png")
1111

1212
res = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
13-
threshold = 0.90
14-
loc = np.whre(res >= threshold)
13+
threshold = 0.80
14+
loc = np.where(res >= threshold)
1515

16-
print(loc)
17-
18-
assert(len(loc[0]) > 0, "No match found.")
16+
assert len(loc[0]) > 0, "No match found."

tests/screenshots/basic.png

57.3 KB
Loading

vm.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@
6666
{ enable = true;
6767
extraConfig = "%wheel ALL=(ALL) NOPASSWD: ALL";
6868
};
69+
70+
### Switch to VirtIO emulated GPU
71+
virtualisation.qemu.options = [
72+
"-vga virtio"
73+
];
6974
}

0 commit comments

Comments
 (0)