Skip to content

Commit e9fe9f9

Browse files
committed
Clean up NixOSContext setup
1 parent 0c9a916 commit e9fe9f9

File tree

4 files changed

+40
-45
lines changed

4 files changed

+40
-45
lines changed

tests/features/environment.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
1-
from steps.common import NixOSNamespace
1+
from types import SimpleNamespace
2+
from pathlib import Path
3+
4+
class NixOSNamespace(SimpleNamespace):
5+
''' Derived version of SimpleNamespace, helps unpack our NixOS test objects
6+
and add utility functions for commonly used test steps.
7+
'''
8+
9+
def __init__(self, context):
10+
self.__dict__.update(**context.config.userdata)
11+
self._base_dir = Path(context.config.base_dir).parent.resolve()
12+
13+
def _gjs_cmdline(self, code):
14+
SHELL_DBUS = "org.gnome.Shell"
15+
SHELL_OBJECT = "/org/gnome/Shell"
16+
EVAL_DBUS = "org.gnome.Shell.Eval"
17+
code_full = f''' paperwm = Main.extensionManager.lookup("paperwm@paperwm.github.com").stateObj; {code} '''
18+
esc_code = code_full.replace('"', '\\"').replace('`', '\\`')
19+
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}\""
20+
21+
def libinput_play(self, recording):
22+
''' Play the specified libinput recording file.
23+
'''
24+
recordFile = self._base_dir / "recordings" / recording
25+
self.machine.succeed("libinput replay --once --replay-after 0 %s" %recordFile)
26+
27+
def gjs_eval(self, code):
28+
''' Execute the specified GJS code from within the GNOME Shell process.
29+
'''
30+
return self.machine.succeed(self._gjs_cmdline(code))
31+
32+
def wait_for_paperwm(self):
33+
''' Wait until GNOME Shell is able to yield PaperWM internal state.
34+
'''
35+
return self.machine.wait_until_succeeds(self._gjs_cmdline('paperwm.findModule("tiling").spaces._initDone'))
236

337
def before_all(context):
438
''' Wait until PaperWM is actually running
539
'''
640
print("Waiting for PaperWM...")
7-
nixos = NixOSNamespace(context)
8-
nixos.wait_for_paperwm()
41+
context.nixos = NixOSNamespace(context)
42+
context.nixos.wait_for_paperwm()

tests/features/steps/basic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from behave import given, when, then
2-
from common import NixOSNamespace
32

43
@when("the machine starts")
54
def machine_boot(context):
6-
nixos = NixOSNamespace(context)
5+
pass
76
# no-op: our test template starts the machine already
87

98
@then("the machine should reach graphics")
109
def graphical_target(context):
11-
nixos = NixOSNamespace(context)
12-
nixos.machine.wait_for_unit("graphical.target")
10+
context.nixos.machine.wait_for_unit("graphical.target")

tests/features/steps/common.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/features/steps/input.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from behave import given, when, then
2-
from common import NixOSNamespace
32

43
@when("the user performs {gesture}")
54
def play_gesture(context, gesture):
6-
nixos = NixOSNamespace(context)
7-
nixos.libinput_play(gesture + ".yaml")
5+
context.nixos.libinput_play(gesture + ".yaml")

0 commit comments

Comments
 (0)