Skip to content

Commit

Permalink
Add vispy test (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Jun 24, 2024
1 parent 80cca60 commit 4cf5c60
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .github/workflows/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
qt: "pyqt5"
- os: ubuntu-24.04
qt: "pyqt6"
- os: windows-latest
qt: "pyqt6"
- os: ubuntu-latest
qt: "pyside6"
runs-on: ${{ matrix.os }}
Expand All @@ -48,11 +50,24 @@ jobs:
if: matrix.qt != ''
run: |
set -eo pipefail
pip install ${{ matrix.qt }} matplotlib
pip install ${{ matrix.qt }} matplotlib qtpy
QT_DEBUG_PLUGINS=1 LIBGL_DEBUG=verbose python tests/test_qt.py
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.qt }}-cube
path: ${{ matrix.os }}-${{ matrix.qt }}-cube.png
if-no-files-found: error
- name: Test Vispy Qt
if: matrix.qt != ''
run: |
pip install vispy pillow pyopengl
python tests/test_vispy_qt.py
env:
MATRIX_OS: ${{ matrix.os }}
MATRIX_QT: ${{ matrix.qt }}
- uses: actions/upload-artifact@v4
if: matrix.qt != ''
with:
name: ${{ matrix.os }}-${{ matrix.qt }}-vispy-volume
path: ${{ matrix.os }}-${{ matrix.qt }}-vispy-volume.png
3 changes: 3 additions & 0 deletions tests/test_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
plt.figure()
backend = matplotlib.get_backend()
assert backend == 'QtAgg', backend

from qtpy import QtDBus
_ = QtDBus.QDBusConnection('Name')
21 changes: 21 additions & 0 deletions tests/test_vispy_qt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Quickly check if vispy off screen plotting works."""

import os
from pathlib import Path
import numpy as np
from qtpy.QtWidgets import QApplication
from vispy import scene
from PIL import Image

qapp = QApplication([])
canvas = scene.SceneCanvas(size=(512, 512))
view = canvas.central_widget.add_view()
np.random.seed(0)
vol_data = np.random.rand(64, 64, 64).astype(np.float32)
image = scene.visuals.Volume(vol_data, cmap="viridis", parent=view.scene)
view.camera = scene.ArcballCamera()
canvas.show()

fname = f'{os.environ['MATRIX_OS']}-{os.environ['MATRIX_QT']}-vispy-volume.png'
out_path = Path(__file__).parent.parent / fname
Image.fromarray(canvas.render()).save(out_path)

0 comments on commit 4cf5c60

Please sign in to comment.