Skip to content

Commit

Permalink
Updated/fixed GUI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Nov 16, 2023
1 parent 81650de commit 1aaa0f6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ jobs:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
envs: |
- linux: py38-test
- linux: py38-test-oldestdeps
- linux: py39-test
- linux: py310-test-novis
- linux: py310-test-viz
- linux: py311-test-all
- linux: py312-test-dev
- macos: py38-test
- macos: py38-test-oldestdeps
- macos: py39-test
- macos: py310-test-novis
- macos: py310-test-viz
- macos: py311-test-all
- macos: py312-test-dev
- windows: py38-test
- windows: py38-test-oldestdeps
- windows: py39-test
- windows: py310-test-novis
- windows: py310-test-viz
- windows: py311-test-all
- windows: py312-test-dev
51 changes: 37 additions & 14 deletions pvextractor/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,45 @@
import pytest
import numpy as np
import matplotlib
from matplotlib.backend_bases import KeyEvent, MouseEvent

from ..gui import PVSlicer

from .test_slicer import make_test_hdu
from .test_slicer import make_test_hdu, make_test_fits_file

MPL_LT_31 = LooseVersion(matplotlib.__version__) < LooseVersion('3.1')
MATPLOTLIB_GE_36 = LooseVersion(matplotlib.__version__) >= LooseVersion('3.6')

def key_press_event(canvas, *event):
if MATPLOTLIB_GE_36:
canvas.callbacks.process('key_press_event',
KeyEvent('key_press_event', canvas, *event))
else:
canvas.key_press_event(*event)


def button_press_event(canvas, *event):
if MATPLOTLIB_GE_36:
canvas.callbacks.process('button_press_event',
MouseEvent('button_press_event', canvas, *event))
else:
canvas.button_press_event(*event)


def motion_notify_event(canvas, *event):
if MATPLOTLIB_GE_36:
canvas.callbacks.process('motion_notify_event',
MouseEvent('motion_notify_event', canvas, *event))
else:
canvas.motion_notify_event(*event)


def test_gui():

# This tests currently segfaults with Matplotlib 3.1 and later
pytest.importorskip('PyQt6')

hdu = make_test_hdu()

pv = PVSlicer(hdu, clim=(-0.02, 2), backend='Qt5Agg')
pv = PVSlicer(hdu, clim=(-0.02, 2), backend='QtAgg')
pv.show(block=False)

xy_data = np.array([[0.0, 0.1, 0.5, 1.0, 0.5],
Expand All @@ -26,12 +50,12 @@ def test_gui():
x, y = pv.ax1.transData.transform(xy_data).T

for i in range(len(x)):
pv.fig.canvas.motion_notify_event(x[i], y[i])
pv.fig.canvas.button_press_event(x[i], y[i], 1)
motion_notify_event(pv.fig.canvas, x[i], y[i])
button_press_event(pv.fig.canvas, x[i], y[i], 1)

pv.fig.canvas.key_press_event('enter')
pv.fig.canvas.motion_notify_event(x[-1] - 20, y[-1])
pv.fig.canvas.button_press_event(x[-1] - 20, y[-1], 1)
key_press_event(pv.fig.canvas, 'enter')
motion_notify_event(pv.fig.canvas, x[-1] - 20, y[-1])
button_press_event(pv.fig.canvas, x[-1] - 20, y[-1], 1)

pv.fig.canvas.draw()

Expand All @@ -40,14 +64,13 @@ def test_gui():
pv.close()


def test_gui_from_fits_filename():
def test_gui_from_fits_filename(tmp_path):

# This tests currently segfaults with Matplotlib 3.1 and later
pytest.importorskip('PyQt6')

fits_filename = make_test_fits_file()
fits_filename = make_test_fits_file(tmp_path)

pv = PVSlicer(fits_filename, clim=(-0.02, 2), backend='Qt5Agg')
pv = PVSlicer(fits_filename, clim=(-0.02, 2), backend='QtAgg')
pv.show(block=False)

pv.close()

4 changes: 2 additions & 2 deletions pvextractor/tests/test_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def make_test_hdu():
return hdu


def make_test_fits_file():
def make_test_fits_file(tmp_path):
hdu = make_test_hdu()
filename = 'example.fits'
filename = tmp_path / 'example.fits'
hdu.writeto(filename)
return filename

Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ install_requires =
[options.extras_require]
test =
pytest-astropy
PyQt5==5.13.*
docs =
sphinx-astropy

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{36,37,38,39}-test{,-oldestdeps,-alldeps,-devdeps,-novis,-cov}
py{36,37,38,39}-test{,-oldestdeps,-alldeps,-devdeps,-viz,-cov}
build_docs
codestyle
requires =
Expand Down Expand Up @@ -31,6 +31,7 @@ deps =
devdeps: numpy>=0.0.dev0
devdeps: astropy>=0.0.dev0
devdeps: spectral-cube @ git+https://github.com/radio-astro-tools/spectral-cube
viz: PyQt6
extras =
test
alldeps: all
Expand Down

0 comments on commit 1aaa0f6

Please sign in to comment.