Also check PyQt version for qtutils.version_check()

With an older PyQt built against a newer Qt, we still don't have its features
available.

This also drops support for exact=True with compiled=True as the semantics for
that are unclear, and it's not used.
This commit is contained in:
Florian Bruhin 2017-10-12 19:11:47 +02:00
parent 4f870f902c
commit dfe2f9e38c
3 changed files with 33 additions and 22 deletions

View File

@ -33,7 +33,8 @@ import contextlib
import pkg_resources import pkg_resources
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray, from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
QIODevice, QSaveFile, QT_VERSION_STR) QIODevice, QSaveFile, QT_VERSION_STR,
PYQT_VERSION_STR)
try: try:
from PyQt5.QtWebKit import qWebKitVersion from PyQt5.QtWebKit import qWebKitVersion
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
@ -82,12 +83,18 @@ def version_check(version, exact=False, compiled=True):
# Catch code using the old API for this # Catch code using the old API for this
assert exact not in [operator.gt, operator.lt, operator.ge, operator.le, assert exact not in [operator.gt, operator.lt, operator.ge, operator.le,
operator.eq], exact operator.eq], exact
if compiled and exact:
raise ValueError("Can't use compiled=True with exact=True!")
parsed = pkg_resources.parse_version(version) parsed = pkg_resources.parse_version(version)
op = operator.eq if exact else operator.ge op = operator.eq if exact else operator.ge
result = op(pkg_resources.parse_version(qVersion()), parsed) result = op(pkg_resources.parse_version(qVersion()), parsed)
if compiled and result: if compiled and result:
# v1 ==/>= parsed, now check if v2 ==/>= parsed too. # qVersion() ==/>= parsed, now check if QT_VERSION_STR ==/>= parsed.
result = op(pkg_resources.parse_version(QT_VERSION_STR), parsed) result = op(pkg_resources.parse_version(QT_VERSION_STR), parsed)
if compiled and result:
# FInally, check PYQT_VERSION_STR as well.
result = op(pkg_resources.parse_version(PYQT_VERSION_STR), parsed)
return result return result

View File

@ -84,10 +84,11 @@ def _get_version_tag(tag):
if package == 'qt': if package == 'qt':
op = match.group('operator') op = match.group('operator')
do_skip = { do_skip = {
'==': not qtutils.version_check(version, exact=True), '==': not qtutils.version_check(version, exact=True,
compiled=False),
'>=': not qtutils.version_check(version), '>=': not qtutils.version_check(version),
'<': qtutils.version_check(version), '<': qtutils.version_check(version),
'!=': qtutils.version_check(version, exact=True), '!=': qtutils.version_check(version, exact=True, compiled=False),
} }
return pytest.mark.skipif(do_skip[op], reason='Needs ' + tag) return pytest.mark.skipif(do_skip[op], reason='Needs ' + tag)
elif package == 'pyqt': elif package == 'pyqt':

View File

@ -39,34 +39,36 @@ from qutebrowser.utils import qtutils, utils
import overflow_test_cases import overflow_test_cases
@pytest.mark.parametrize('qversion, compiled, version, exact, expected', [ @pytest.mark.parametrize(['qversion', 'compiled', 'pyqt', 'version', 'exact',
'expected'], [
# equal versions # equal versions
('5.4.0', None, '5.4.0', False, True), ('5.4.0', None, None, '5.4.0', False, True),
('5.4.0', None, '5.4.0', True, True), # exact=True ('5.4.0', None, None, '5.4.0', True, True), # exact=True
('5.4.0', None, '5.4', True, True), # without trailing 0 ('5.4.0', None, None, '5.4', True, True), # without trailing 0
# newer version installed # newer version installed
('5.4.1', None, '5.4', False, True), ('5.4.1', None, None, '5.4', False, True),
('5.4.1', None, '5.4', True, False), # exact=True ('5.4.1', None, None, '5.4', True, False), # exact=True
# older version installed # older version installed
('5.3.2', None, '5.4', False, False), ('5.3.2', None, None, '5.4', False, False),
('5.3.0', None, '5.3.2', False, False), ('5.3.0', None, None, '5.3.2', False, False),
('5.3.0', None, '5.3.2', True, False), # exact=True ('5.3.0', None, None, '5.3.2', True, False), # exact=True
# strict # compiled=True
('5.4.0', '5.3.0', '5.4.0', False, False), # new Qt runtime, but compiled against older version
('5.4.0', '5.4.0', '5.4.0', False, True), ('5.4.0', '5.3.0', '5.4.0', '5.4.0', False, False),
# strict and exact=True # new Qt runtime, compiled against new version, but old PyQt
('5.4.0', '5.5.0', '5.4.0', True, False), ('5.4.0', '5.4.0', '5.3.0', '5.4.0', False, False),
('5.5.0', '5.4.0', '5.4.0', True, False), # all up-to-date
('5.4.0', '5.4.0', '5.4.0', True, True), ('5.4.0', '5.4.0', '5.4.0', '5.4.0', False, True),
]) ])
def test_version_check(monkeypatch, qversion, compiled, version, exact, def test_version_check(monkeypatch, qversion, compiled, pyqt, version, exact,
expected): expected):
"""Test for version_check(). """Test for version_check().
Args: Args:
monkeypatch: The pytest monkeypatch fixture. monkeypatch: The pytest monkeypatch fixture.
qversion: The version to set as fake qVersion(). qversion: The version to set as fake qVersion().
compiled: The value for QT_VERSION_STR (set strict=True) compiled: The value for QT_VERSION_STR (set compiled=False)
pyqt: The value for PYQT_VERSION_STR (set compiled=False)
version: The version to compare with. version: The version to compare with.
exact: Use exact comparing (==) exact: Use exact comparing (==)
expected: The expected result. expected: The expected result.
@ -74,6 +76,7 @@ def test_version_check(monkeypatch, qversion, compiled, version, exact,
monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion) monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion)
if compiled is not None: if compiled is not None:
monkeypatch.setattr(qtutils, 'QT_VERSION_STR', compiled) monkeypatch.setattr(qtutils, 'QT_VERSION_STR', compiled)
monkeypatch.setattr(qtutils, 'PYQT_VERSION_STR', pyqt)
compiled_arg = True compiled_arg = True
else: else:
compiled_arg = False compiled_arg = False