Skip to content

Commit

Permalink
Raise warnings when importing QtHelp or QtMultimedia with PySide2
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaverde committed Aug 21, 2017
1 parent 77407aa commit 3c31109
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
5 changes: 4 additions & 1 deletion qtpy/QtHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions qtpy/QtMultimedia.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions qtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 18 additions & 2 deletions qtpy/tests/test_qthelp.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
18 changes: 17 additions & 1 deletion qtpy/tests/test_qtmultimedia.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3c31109

Please sign in to comment.