import pytest
from distutils.version import LooseVersion
import matplotlib as mpl


from ..gui import PVSlicer

from .test_slicer import make_test_hdu

try:
    import PyQt5
    PYQT5OK = True
except ImportError:
    PYQT5OK = False


if LooseVersion(mpl.__version__) < LooseVersion('2'):
    MPLOK = True
else:
    MPLOK = False


@pytest.mark.skipif('not PYQT5OK or not MPLOK')
def test_gui():
    hdu = make_test_hdu()

    pv = PVSlicer(hdu, clim=(-0.02, 2))
    pv.show(block=False)

    x = [100, 200, 220, 330, 340]
    y = [100, 200, 300, 420, 430]

    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)

    pv.fig.canvas.key_press_event('enter')
    pv.fig.canvas.motion_notify_event(310, 420)
    pv.fig.canvas.button_press_event(410, 420, 1)

    pv.fig.canvas.draw()

    assert pv.pv_slice.data.shape == (5, 2)

@@ -4,380 +4,88 @@
 ort 
-pytest%0Afrom distutils.version import LooseVersion%0Aimport matplotlib as mpl%0A%0A%0Afrom ..gui import PVSlicer%0A%0Afrom .test_slicer import make_test_hdu%0A%0Atry:%0A    import PyQt5%0A    PYQT5OK = True%0Aexcept ImportError:%0A    PYQT5OK = False%0A%0A%0Aif LooseVersion(mpl.__version__) %3C LooseVersion('2'):%0A    MPLOK = True%0Aelse:%0A    MPLOK = False%0A%0A%0A@pytest.mark.skipif('not PYQT5OK or not MPLOK')
+numpy as np%0Afrom ..gui import PVSlicer%0A%0Afrom .test_slicer import make_test_hdu%0A%0A
 %0Adef
@@ -97,16 +97,17 @@
 _gui():%0A
+%0A
     hdu 
@@ -200,70 +200,157 @@
    x
- = %5B100, 200, 220, 330, 340%5D%0A    y = %5B100, 200, 300, 420, 430%5D
+y_data = np.array(%5B%5B0.0, 0.1, 0.5, 1.0, 0.5%5D,%0A                        %5B0.0, 0.3, 0.4, 0.9, 1.4%5D%5D).T%0A%0A    x, y = pv.ax1.transData.transform(xy_data).T
 %0A%0A  
@@ -571,16 +571,25 @@
 ent(
-310, 420
+x%5B-1%5D - 20, y%5B-1%5D
 )%0A  
@@ -627,16 +627,25 @@
 ent(
-410, 420
+x%5B-1%5D - 20, y%5B-1%5D
 , 1)

Make GUI test more robust to HiDPI displays