Skip to content

Commit 3e76783

Browse files
committed
Add basic GUI tests
1 parent 46d3989 commit 3e76783

File tree

8 files changed

+471
-42
lines changed

8 files changed

+471
-42
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@ jobs:
2626
with:
2727
python-version: "${{ matrix.python-version }}"
2828

29-
- name: "Install dependencies in pyproject.toml"
29+
- name: "Install test and project dependencies"
3030
run: |
31+
# Project dependencies from pyproject.toml
32+
# NOTE: Also builds viscm. How do we avoid this?
3133
pip install .
32-
pip install pytest pytest-cov ${{ matrix.pyqt-dependency }}
34+
35+
# Test dependencies
36+
pip install pytest pytest-cov pytest-qt pytest-xvfb ${{ matrix.pyqt-dependency }}
37+
# pytest-qt CI dependencies: https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html#github-actions
38+
sudo apt update
39+
sudo apt install -y \
40+
xvfb \
41+
libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 x11-utils
3342
3443
- name: "Run tests"
3544
run: "make test"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: test
22
test:
33
python -m pytest --version
4-
python -m pytest -v test/
4+
python -m pytest --xvfb-backend=xvfb -v test/
55

66

77
.PHONY: lint

doc/contributing.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,37 @@
22

33
Install development dependencies:
44

5-
```
5+
```bash
66
conda env create # or `mamba env create`
77
```
88

99

1010
## Development install
1111

12-
```
12+
```bash
1313
pip install -e .
1414
```
1515

1616

1717
## Testing the build
1818

19-
```
19+
```bash
2020
rm -rf dist
2121
python -m build
2222
pip install dist/*.whl # or `dist/*.tar.gz`
2323
```
2424

2525

26-
## Code formatting and linting
26+
## Tests
27+
28+
See `Makefile` for convenience commands.
29+
30+
31+
### Code linting (and formatting)
32+
33+
```bash
34+
make lint
35+
```
2736

2837
This codebase uses [black](https://black.readthedocs.io/en/stable/) and
2938
[ruff](https://github.com/charliermarsh/ruff) to automatically format and lint the code.
@@ -37,3 +46,18 @@ and then another commit should immediately follow which updates
3746
`.git-blame-ignore-revs`. For example:
3847
[1fec42d](https://github.com/matplotlib/viscm/pull/64/commits/1fec42d0baf90e00d510efd76cb6006fa0c70dc4),
3948
[8aa7bb0](https://github.com/matplotlib/viscm/pull/64/commits/8aa7bb01440aeca6f8bbcefe0671c28f2ce284c6).
49+
50+
51+
### Unit tests
52+
53+
```bash
54+
make test
55+
```
56+
57+
Unit tests require `xvfb` (X Virtual Framebuffer) to test the GUI. If `xvfb` is not
58+
installed, you'll receive `ERROR: xvfb backend xvfb requested but not installed`.
59+
Install with:
60+
61+
```bash
62+
sudo apt install xvfb
63+
```

test/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def tests_data_dir() -> Path:
8+
tests_dir = Path(__file__).parent.resolve()
9+
tests_data_dir = tests_dir / "data"
10+
return tests_data_dir

0 commit comments

Comments
 (0)