Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from astrofrog/enable-tests
Make tests.py into proper unit test, and add Qt version info to pytest header
- Loading branch information
Showing
4 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
|
||
|
||
def pytest_configure(config): | ||
""" | ||
This function gets run by py.test at the very start | ||
""" | ||
|
||
if 'USE_QT_API' in os.environ: | ||
os.environ['QT_API'] = os.environ['USE_QT_API'].lower() | ||
|
||
# We need to import qtpy here to make sure that the API versions get set | ||
# straight away. | ||
import qtpy | ||
|
||
|
||
def pytest_report_header(config): | ||
""" | ||
This function is used by py.test to insert a customized header into the | ||
test report. | ||
""" | ||
|
||
versions = os.linesep | ||
versions += 'PyQt4: ' | ||
|
||
try: | ||
from PyQt4 import Qt | ||
versions += "PyQt: {0} - Qt: {1}".format(Qt.PYQT_VERSION_STR, Qt.QT_VERSION_STR) | ||
except ImportError: | ||
versions += 'not installed' | ||
except AttributeError: | ||
versions += 'unknown version' | ||
|
||
versions += os.linesep | ||
versions += 'PyQt5: ' | ||
|
||
try: | ||
from PyQt5 import Qt | ||
versions += "PyQt: {0} - Qt: {1}".format(Qt.PYQT_VERSION_STR, Qt.QT_VERSION_STR) | ||
except ImportError: | ||
versions += 'not installed' | ||
except AttributeError: | ||
versions += 'unknown version' | ||
|
||
versions += os.linesep | ||
versions += 'PySide: ' | ||
|
||
try: | ||
import PySide | ||
from PySide import QtCore | ||
versions += "PySide: {0} - Qt: {1}".format(PySide.__version__, QtCore.__version__) | ||
except ImportError: | ||
versions += 'not installed' | ||
except AttributeError: | ||
versions += 'unknown version' | ||
|
||
versions += os.linesep | ||
|
||
return versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
|
||
from qtpy import QtCore, QtGui, QtWidgets, QtWebEngineWidgets | ||
|
||
|
||
def assert_pyside(): | ||
""" | ||
Make sure that we are using PySide | ||
""" | ||
import PySide | ||
assert QtCore.QEvent is PySide.QtCore.QEvent | ||
assert QtGui.QPainter is PySide.QtGui.QPainter | ||
assert QtWidgets.QWidget is PySide.QtGui.QWidget | ||
assert QtWebEngineWidgets.QWebEnginePage is PySide.QtWebKit.QWebPage | ||
|
||
|
||
def assert_pyqt4(): | ||
""" | ||
Make sure that we are using PyQt4 | ||
""" | ||
import PyQt4 | ||
assert QtCore.QEvent is PyQt4.QtCore.QEvent | ||
assert QtGui.QPainter is PyQt4.QtGui.QPainter | ||
assert QtWidgets.QWidget is PyQt4.QtGui.QWidget | ||
assert QtWebEngineWidgets.QWebEnginePage is PyQt4.QtWebKit.QWebPage | ||
|
||
|
||
def assert_pyqt5(): | ||
""" | ||
Make sure that we are using PyQt5 | ||
""" | ||
import PyQt5 | ||
assert QtCore.QEvent is PyQt5.QtCore.QEvent | ||
assert QtGui.QPainter is PyQt5.QtGui.QPainter | ||
assert QtWidgets.QWidget is PyQt5.QtWidgets.QWidget | ||
assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebKitWidgets.QWebPage | ||
|
||
|
||
def test_qt_api(): | ||
""" | ||
If QT_API is specified, we check that the correct Qt wrapper was used | ||
""" | ||
|
||
QT_API = os.environ.get('QT_API') | ||
|
||
if QT_API == 'pyside': | ||
assert_pyside() | ||
elif QT_API in ('pyqt', 'pyqt4'): | ||
assert_pyqt4() | ||
elif QT_API == 'pyqt5': | ||
assert_pyqt5() | ||
else: | ||
# If the tests are run locally, USE_QT_API and QT_API may not be | ||
# defined, but we still want to make sure qtpy is behaving sensibly. | ||
# We should then be loading, in order of decreasing preference, PyQt5, | ||
# PyQt4, and PySide. | ||
try: | ||
import PyQt5 | ||
except ImportError: | ||
try: | ||
import PyQt4 | ||
except ImportError: | ||
import PySide | ||
assert_pyside() | ||
else: | ||
assert_pyqt4() | ||
else: | ||
assert_pyqt5() |
This file was deleted.
Oops, something went wrong.