diff --git a/qtpy/QtHelp.py b/qtpy/QtHelp.py index 7830d412..abe0aae9 100644 --- a/qtpy/QtHelp.py +++ b/qtpy/QtHelp.py @@ -7,17 +7,20 @@ """QtHelp Wrapper.""" +import warnings + from . import PYQT5 from . import PYQT4 from . import PYSIDE from . import PYSIDE2 +from . import PythonQtWarning if PYQT5: from PyQt5.QtHelp import * elif PYSIDE2: # Current wheels don't have this module # from PySide2.QtHelp - pass + warnings.warn("QtHelp binding is missing in PySide2", PythonQtWarning) elif PYQT4: from PyQt4.QtHelp import * elif PYSIDE: diff --git a/qtpy/QtMultimedia.py b/qtpy/QtMultimedia.py index a20cc3bd..47dd090f 100644 --- a/qtpy/QtMultimedia.py +++ b/qtpy/QtMultimedia.py @@ -1,15 +1,17 @@ +import warnings + from . import PYQT5 from . import PYQT4 from . import PYSIDE from . import PYSIDE2 - +from . import PythonQtWarning if PYQT5: from PyQt5.QtMultimedia import * elif PYSIDE2: # Current wheels don't have this module # from PySide2.QtMultimedia import * - pass + warnings.warn("QtMultimedia binding is missing in PySide2", PythonQtWarning) elif PYQT4: from PyQt4.QtMultimedia import * from PyQt4.QtGui import QSound diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 1ade9a8c..ab510af3 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -98,6 +98,9 @@ class PythonQtError(Exception): """Error raise if no bindings could be selected""" pass +class PythonQtWarning(Warning): + """Warning if somefearures are not implemented in a binding.""" + pass if API in PYQT5_API: try: diff --git a/qtpy/tests/test_qthelp.py b/qtpy/tests/test_qthelp.py index c548ebc0..07ee1e0f 100644 --- a/qtpy/tests/test_qthelp.py +++ b/qtpy/tests/test_qthelp.py @@ -1,14 +1,17 @@ """Test for QtHelp namespace.""" from __future__ import absolute_import +import warnings import pytest -from qtpy import PYSIDE2, QtHelp +from qtpy import PYSIDE2, PythonQtWarning -@pytest.mark.skipif(PYSIDE2, reason="QtHelp bind is missing in PySide2") +@pytest.mark.skipif(PYSIDE2, reason="QtHelp binding is missing in PySide2") def test_qthelp(): """Test the qtpy.QtHelp namespace.""" + from qtpy import QtHelp + assert QtHelp.QHelpContentItem is not None assert QtHelp.QHelpContentModel is not None assert QtHelp.QHelpContentWidget is not None @@ -20,3 +23,16 @@ def test_qthelp(): assert QtHelp.QHelpSearchQuery is not None assert QtHelp.QHelpSearchQueryWidget is not None assert QtHelp.QHelpSearchResultWidget is not None + + +@pytest.mark.skipif(not PYSIDE2, reason="Only runs in not implemented bindings") +def test_qthelp_not_implemented(): + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always") + # Try to import QtHelp. + from qtpy import QtHelp + + assert len(w) == 1 + assert issubclass(w[-1].category, PythonQtWarning) + assert "missing" in str(w[-1].message) diff --git a/qtpy/tests/test_qtmultimedia.py b/qtpy/tests/test_qtmultimedia.py index 5561e77b..fcebed9c 100644 --- a/qtpy/tests/test_qtmultimedia.py +++ b/qtpy/tests/test_qtmultimedia.py @@ -1,14 +1,30 @@ from __future__ import absolute_import import pytest -from qtpy import PYSIDE2, QtMultimedia +import warnings +from qtpy import PYSIDE2, PythonQtWarning @pytest.mark.skipif(PYSIDE2, reason="It fails on PySide2") def test_qtmultimedia(): """Test the qtpy.QtMultimedia namespace""" + from qtpy import QtMultimedia + assert QtMultimedia.QAbstractVideoBuffer is not None assert QtMultimedia.QAudio is not None assert QtMultimedia.QAudioDeviceInfo is not None assert QtMultimedia.QAudioInput is not None assert QtMultimedia.QSound is not None + + +@pytest.mark.skipif(not PYSIDE2, reason="Only runs in not implemented bindings") +def test_qtmultimedia_not_implemented(): + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always") + # Try to import QtMultimedia. + from qtpy import QtMultimedia + + assert len(w) == 1 + assert issubclass(w[-1].category, PythonQtWarning) + assert "missing" in str(w[-1].message)