a6971c768d
To reduce complexity, and make it easier to add more images and tests, the images in the `test-data` repository should be merged with the main repository. Furthermore, we can remove a lot of the subprocess work in the image_testing.py file, as we no longer need to have it interact with git. The images are not the same. Images were regenerated with Qt6, and now have proper big and little endian handling thanks to @pijyoi Second commit is a slightly modified variant of 2e135ab282d6007b34a3854921be54d0e9efb241 authored by @pijyoi it is to convert qimages to RGBA8888 for testing. Image files were regenerated images for the big/little handling Fixed issue with bogus test from test_NonUniformImage and generated a new image
70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
import time
|
|
from pyqtgraph.Qt import QtCore, QtGui, QtTest
|
|
|
|
|
|
def resizeWindow(win, w, h, timeout=2.0):
|
|
"""Resize a window and wait until it has the correct size.
|
|
|
|
This is required for unit testing on some platforms that do not guarantee
|
|
immediate response from the windowing system.
|
|
"""
|
|
QtGui.QApplication.processEvents()
|
|
# Sometimes the window size will switch multiple times before settling
|
|
# on its final size. Adding qWaitForWindowExposed seems to help with this.
|
|
QtTest.QTest.qWaitForWindowExposed(win)
|
|
win.resize(w, h)
|
|
start = time.time()
|
|
while True:
|
|
w1, h1 = win.width(), win.height()
|
|
if (w,h) == (w1,h1):
|
|
return
|
|
QtTest.QTest.qWait(10)
|
|
if time.time()-start > timeout:
|
|
raise TimeoutError("Window resize failed (requested %dx%d, got %dx%d)" % (w, h, w1, h1))
|
|
|
|
|
|
# Functions for generating user input events.
|
|
# We would like to use QTest for this purpose, but it seems to be broken.
|
|
# See: http://stackoverflow.com/questions/16299779/qt-qgraphicsview-unit-testing-how-to-keep-the-mouse-in-a-pressed-state
|
|
|
|
def mousePress(widget, pos, button, modifier=None):
|
|
if isinstance(widget, QtGui.QGraphicsView):
|
|
widget = widget.viewport()
|
|
if modifier is None:
|
|
modifier = QtCore.Qt.NoModifier
|
|
event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, pos, button, QtCore.Qt.NoButton, modifier)
|
|
QtGui.QApplication.sendEvent(widget, event)
|
|
|
|
|
|
def mouseRelease(widget, pos, button, modifier=None):
|
|
if isinstance(widget, QtGui.QGraphicsView):
|
|
widget = widget.viewport()
|
|
if modifier is None:
|
|
modifier = QtCore.Qt.NoModifier
|
|
event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonRelease, pos, button, QtCore.Qt.NoButton, modifier)
|
|
QtGui.QApplication.sendEvent(widget, event)
|
|
|
|
|
|
def mouseMove(widget, pos, buttons=None, modifier=None):
|
|
if isinstance(widget, QtGui.QGraphicsView):
|
|
widget = widget.viewport()
|
|
if modifier is None:
|
|
modifier = QtCore.Qt.NoModifier
|
|
if buttons is None:
|
|
buttons = QtCore.Qt.NoButton
|
|
event = QtGui.QMouseEvent(QtCore.QEvent.MouseMove, pos, QtCore.Qt.NoButton, buttons, modifier)
|
|
QtGui.QApplication.sendEvent(widget, event)
|
|
|
|
|
|
def mouseDrag(widget, pos1, pos2, button, modifier=None):
|
|
mouseMove(widget, pos1)
|
|
mousePress(widget, pos1, button, modifier)
|
|
mouseMove(widget, pos2, button, modifier)
|
|
mouseRelease(widget, pos2, button, modifier)
|
|
|
|
|
|
def mouseClick(widget, pos, button, modifier=None):
|
|
mouseMove(widget, pos)
|
|
mousePress(widget, pos, button, modifier)
|
|
mouseRelease(widget, pos, button, modifier)
|