Skip to content

Commit 57ed6bb

Browse files
committed
Add tentative GitHub workflow and OpenCV
1 parent 4adc11e commit 57ed6bb

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.github/workflows/testing.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Run end-to-end tests for PaperWM"
2+
3+
on:
4+
push:
5+
paths:
6+
- '*.nix'
7+
- '*.js'
8+
- 'tests/**'
9+
10+
jobs:
11+
run-tests:
12+
name: Run unit tests
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
- name: Set up Nix
18+
uses: cachix/install-nix-action@v20
19+
- name: Enable KVM group perms
20+
run: |
21+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
22+
sudo udevadm control --reload-rules
23+
sudo udevadm trigger --name-match=kvm
24+
sudo tee /etc/nix/nix.conf <<< "extra-system-features = kvm nixos-test"
25+
- name: Build test VM
26+
run: |
27+
nix build .#vm
28+
- name: Launch tests
29+
run: |
30+
for file in tests/features/*.feature
31+
do
32+
echo "::group::Test ${file##*/}"
33+
feat="${file##*/}"
34+
nix --extra-experimental-features "nix-command flakes" run .#checks.x86_64-linux.${feat%%.feature}.driver
35+
echo "::endgroup::"
36+
done

tests/features/environment.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33
from behave import fixture, use_fixture
44

5+
import cv2
6+
57
class NixOSNamespace(SimpleNamespace):
68
''' Derived version of SimpleNamespace, helps unpack our NixOS test objects
79
and add utility functions for commonly used test steps.
@@ -10,6 +12,7 @@ class NixOSNamespace(SimpleNamespace):
1012
def __init__(self, context):
1113
self.__dict__.update(**context.config.userdata)
1214
self._base_dir = Path(context.config.base_dir).parent.resolve()
15+
self._context = context
1316

1417
def _gjs_cmdline(self, code):
1518
SHELL_DBUS = "org.gnome.Shell"
@@ -35,6 +38,13 @@ def wait_for_paperwm(self):
3538
'''
3639
return self.machine.wait_until_succeeds(self._gjs_cmdline('paperwm.findModule("tiling").spaces._initDone'))
3740

41+
def screenshot(self):
42+
''' Take a screenshot and load it as an OpenCV-compatible representation
43+
'''
44+
filename = f"scenario-{self._context.scenario.line}.png"
45+
self.machine.screenshot(filename)
46+
return cv2.imread(filename)
47+
3848
@fixture
3949
def shell(context):
4050
''' Wait for PaperWM to start

tests/template.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name = featureName;
88
nodes = { machine = defaultConfig; };
99

10-
extraPythonPackages = p: with p; [ behave ];
10+
extraPythonPackages = p: with p; [ behave opencv-python ];
1111

1212
skipTypeCheck = true;
1313

0 commit comments

Comments
 (0)