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)

import numpy as np
from ..gui import PVSlicer

from .test_slicer import make_test_hdu


def test_gui():

    hdu = make_test_hdu()

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

    xy_data = np.array([[0.0, 0.1, 0.5, 1.0, 0.5],
                        [0.0, 0.3, 0.4, 0.9, 1.4]]).T

    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)

    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)

    pv.fig.canvas.draw()

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

Make GUI test more robust to HiDPI displays
Make GUI test more robust to HiDPI displays
+ import numpy as np
- 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
  
+ def test_gui():
  
- 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]
+     xy_data = np.array([[0.0, 0.1, 0.5, 1.0, 0.5],
+                         [0.0, 0.3, 0.4, 0.9, 1.4]]).T
+ 
+     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)
  
      pv.fig.canvas.key_press_event('enter')
-     pv.fig.canvas.motion_notify_event(310, 420)
+     pv.fig.canvas.motion_notify_event(x[-1] - 20, y[-1])
-     pv.fig.canvas.button_press_event(410, 420, 1)
+     pv.fig.canvas.button_press_event(x[-1] - 20, y[-1], 1)
  
      pv.fig.canvas.draw()
  
      assert pv.pv_slice.data.shape == (5, 2)
  
Make GUI test more robust to HiDPI displays
## Code Before:
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)

## Instruction:
Make GUI test more robust to HiDPI displays
## Code After:
import numpy as np
from ..gui import PVSlicer

from .test_slicer import make_test_hdu


def test_gui():

    hdu = make_test_hdu()

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

    xy_data = np.array([[0.0, 0.1, 0.5, 1.0, 0.5],
                        [0.0, 0.3, 0.4, 0.9, 1.4]]).T

    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)

    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)

    pv.fig.canvas.draw()

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