Skip to content

Commit

Permalink
Added viewer test
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Nov 15, 2024
1 parent 58dea3b commit 4ca855d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
40 changes: 40 additions & 0 deletions astrodendro/tests/test_viewer.py
Original file line number Diff line number Diff line change
@@ -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 == ""
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/
Expand All @@ -30,6 +32,7 @@ deps =
oldestdeps: matplotlib==3.3.*
oldestdeps: numpy==1.20.*
oldestdeps: pillow==8.0.*
viewer: PyQt6

extras =
test
Expand Down

0 comments on commit 4ca855d

Please sign in to comment.