diff --git a/echo/qt/tests/helpers.py b/echo/qt/tests/helpers.py new file mode 100644 index 00000000..9d903a29 --- /dev/null +++ b/echo/qt/tests/helpers.py @@ -0,0 +1,21 @@ +__all__ = [ + "PYQT5_INSTALLED", "PYQT6_INSTALLED", + "PYSIDE2_INSTALLED", "PYSIDE6_INSTALLED", + "QTPY_INSTALLED", "QT_INSTALLED", + "SKIP_QT_TEST" +] + +def package_installed(package): + try: + __import__(package) + return True + except ImportError: + return False + +PYQT5_INSTALLED = package_installed("PyQt5") +PYQT6_INSTALLED = package_installed("PyQt6") +PYSIDE2_INSTALLED = package_installed("PySide2") +PYSIDE6_INSTALLED = package_installed("PySide6") +QTPY_INSTALLED = package_installed("qtpy") +QT_INSTALLED = PYQT5_INSTALLED or PYQT6_INSTALLED or PYSIDE2_INSTALLED or PYSIDE6_INSTALLED +SKIP_QT_TEST = not (QTPY_INSTALLED and QT_INSTALLED) diff --git a/echo/qt/tests/test_autoconnect.py b/echo/qt/tests/test_autoconnect.py index 69177766..4218d60a 100644 --- a/echo/qt/tests/test_autoconnect.py +++ b/echo/qt/tests/test_autoconnect.py @@ -1,11 +1,17 @@ from datetime import datetime +import pytest from numpy import datetime64 + +from echo import CallbackProperty +from echo.qt.tests.helpers import SKIP_QT_TEST + +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + from qtpy import QtWidgets, QtGui from qtpy.QtCore import QDateTime, Qt - from echo.qt.autoconnect import autoconnect_callbacks_to_qt -from echo import CallbackProperty from echo.qt.connect import UserDataWrapper diff --git a/echo/qt/tests/test_connect.py b/echo/qt/tests/test_connect.py index d1b0f919..ee652267 100644 --- a/echo/qt/tests/test_connect.py +++ b/echo/qt/tests/test_connect.py @@ -4,10 +4,14 @@ from numpy import datetime64 from unittest.mock import MagicMock +from echo import CallbackProperty +from echo.qt.tests.helpers import SKIP_QT_TEST + +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + from qtpy import QtWidgets from qtpy.QtCore import QDateTime, Qt - -from echo import CallbackProperty from echo.qt.connect import (connect_checkable_button, connect_datetime, connect_text, connect_combo_data, connect_combo_text, connect_float_text, connect_value, connect_button, @@ -16,6 +20,8 @@ def test_connect_checkable_button(): + + class Test(object): a = CallbackProperty() b = CallbackProperty(True) diff --git a/echo/qt/tests/test_connect_combo_selection.py b/echo/qt/tests/test_connect_combo_selection.py index 6233151a..37c7cb11 100644 --- a/echo/qt/tests/test_connect_combo_selection.py +++ b/echo/qt/tests/test_connect_combo_selection.py @@ -1,10 +1,13 @@ import pytest import numpy as np -from qtpy import QtWidgets - from echo.core import CallbackProperty from echo.selection import SelectionCallbackProperty, ChoiceSeparator +from echo.qt.tests.helpers import SKIP_QT_TEST +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + +from qtpy import QtWidgets from echo.qt.connect import connect_combo_selection diff --git a/echo/qt/tests/test_connect_list_selection.py b/echo/qt/tests/test_connect_list_selection.py index b1caf715..8c6a8f39 100644 --- a/echo/qt/tests/test_connect_list_selection.py +++ b/echo/qt/tests/test_connect_list_selection.py @@ -1,11 +1,14 @@ import pytest import numpy as np -from qtpy import QtWidgets -from qtpy.QtCore import Qt - from echo.core import CallbackProperty from echo.selection import SelectionCallbackProperty, ChoiceSeparator +from echo.qt.tests.helpers import SKIP_QT_TEST +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + +from qtpy import QtWidgets +from qtpy.QtCore import Qt from echo.qt.connect import connect_list_selection diff --git a/tox.ini b/tox.ini index 63ec27be..57e4dbae 100644 --- a/tox.ini +++ b/tox.ini @@ -12,6 +12,7 @@ changedir = test: .tmp/{envname} docs: doc deps = + pyqt{510,511,512,513,514,515,63},pyside{513,514,515,63}: qtpy>=2.0 pyqt510: PyQt5==5.10.* pyqt511: PyQt5==5.11.* pyqt512: PyQt5==5.12.*