diff --git a/astrodendro/tests/test_viewer.py b/astrodendro/tests/test_viewer.py new file mode 100644 index 0000000..b6ad4b7 --- /dev/null +++ b/astrodendro/tests/test_viewer.py @@ -0,0 +1,40 @@ +import pytest +import numpy as np + +import matplotlib.pyplot as plt +from ..dendrogram import Dendrogram +from matplotlib.backend_bases import MouseEvent + + +DATA = np.array([[1, 3, 4, 4, 1, 4], + [1, 2, 3, 2, 1, 3], + [2, 1, 1, 3, 1, 2], + [1, 1, 1, 1, 1, 1], + [2, 3, 2, 1, 1, 2], + [2, 3, 5, 3, 1, 1]]) + +def test_viewer(capsys): + + original_backend = plt.get_backend() + + try: + plt.switch_backend('qtagg') + except ImportError: + pytest.skip("This test requires Qt to be installed") + + d = Dendrogram.compute(DATA) + viewer = d.viewer() + + plt.show(block=False) + + cb = viewer.fig.canvas.callbacks + + cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 660, 520, 1)) + cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 890, 800, 1)) + cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 700, 700, 1)) + + plt.switch_backend(original_backend) + + captured = capsys.readouterr() + assert captured.out == "" + assert captured.err == "" diff --git a/tox.ini b/tox.ini index c344359..a8b89f7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{38,39,310,311}-test{,-alldeps,-devdeps}{,-cov} + py{38,39,310,311}-test{,-alldeps,-devdeps,-viewer}{,-cov} build_docs linkcheck codestyle @@ -10,6 +10,8 @@ requires = isolated_build = true [testenv] +passenv = + DISPLAY setenv = MPLBACKEND=agg devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/ @@ -30,6 +32,7 @@ deps = oldestdeps: matplotlib==3.3.* oldestdeps: numpy==1.20.* oldestdeps: pillow==8.0.* + viewer: PyQt6 extras = test