|
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')) |
2 | 36 |
|
3 | 37 | def before_all(context): |
4 | 38 | ''' Wait until PaperWM is actually running |
5 | 39 | ''' |
6 | 40 | print("Waiting for PaperWM...") |
7 | | - nixos = NixOSNamespace(context) |
8 | | - nixos.wait_for_paperwm() |
| 41 | + context.nixos = NixOSNamespace(context) |
| 42 | + context.nixos.wait_for_paperwm() |
0 commit comments