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:
parent
4f870f902c
commit
dfe2f9e38c
@ -33,7 +33,8 @@ import contextlib
|
||||
|
||||
import pkg_resources
|
||||
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
|
||||
QIODevice, QSaveFile, QT_VERSION_STR)
|
||||
QIODevice, QSaveFile, QT_VERSION_STR,
|
||||
PYQT_VERSION_STR)
|
||||
try:
|
||||
from PyQt5.QtWebKit import qWebKitVersion
|
||||
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
|
||||
assert exact not in [operator.gt, operator.lt, operator.ge, operator.le,
|
||||
operator.eq], exact
|
||||
if compiled and exact:
|
||||
raise ValueError("Can't use compiled=True with exact=True!")
|
||||
|
||||
parsed = pkg_resources.parse_version(version)
|
||||
op = operator.eq if exact else operator.ge
|
||||
result = op(pkg_resources.parse_version(qVersion()), parsed)
|
||||
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)
|
||||
if compiled and result:
|
||||
# FInally, check PYQT_VERSION_STR as well.
|
||||
result = op(pkg_resources.parse_version(PYQT_VERSION_STR), parsed)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -84,10 +84,11 @@ def _get_version_tag(tag):
|
||||
if package == 'qt':
|
||||
op = match.group('operator')
|
||||
do_skip = {
|
||||
'==': not qtutils.version_check(version, exact=True),
|
||||
'==': not qtutils.version_check(version, exact=True,
|
||||
compiled=False),
|
||||
'>=': not 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)
|
||||
elif package == 'pyqt':
|
||||
|
@ -39,34 +39,36 @@ from qutebrowser.utils import qtutils, utils
|
||||
import overflow_test_cases
|
||||
|
||||
|
||||
@pytest.mark.parametrize('qversion, compiled, version, exact, expected', [
|
||||
@pytest.mark.parametrize(['qversion', 'compiled', 'pyqt', 'version', 'exact',
|
||||
'expected'], [
|
||||
# equal versions
|
||||
('5.4.0', None, '5.4.0', False, True),
|
||||
('5.4.0', 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.0', False, True),
|
||||
('5.4.0', None, None, '5.4.0', True, True), # exact=True
|
||||
('5.4.0', None, None, '5.4', True, True), # without trailing 0
|
||||
# newer version installed
|
||||
('5.4.1', None, '5.4', False, True),
|
||||
('5.4.1', None, '5.4', True, False), # exact=True
|
||||
('5.4.1', None, None, '5.4', False, True),
|
||||
('5.4.1', None, None, '5.4', True, False), # exact=True
|
||||
# older version installed
|
||||
('5.3.2', None, '5.4', False, False),
|
||||
('5.3.0', None, '5.3.2', False, False),
|
||||
('5.3.0', None, '5.3.2', True, False), # exact=True
|
||||
# strict
|
||||
('5.4.0', '5.3.0', '5.4.0', False, False),
|
||||
('5.4.0', '5.4.0', '5.4.0', False, True),
|
||||
# strict and exact=True
|
||||
('5.4.0', '5.5.0', '5.4.0', True, False),
|
||||
('5.5.0', '5.4.0', '5.4.0', True, False),
|
||||
('5.4.0', '5.4.0', '5.4.0', True, True),
|
||||
('5.3.2', None, None, '5.4', False, False),
|
||||
('5.3.0', None, None, '5.3.2', False, False),
|
||||
('5.3.0', None, None, '5.3.2', True, False), # exact=True
|
||||
# compiled=True
|
||||
# new Qt runtime, but compiled against older version
|
||||
('5.4.0', '5.3.0', '5.4.0', '5.4.0', False, False),
|
||||
# new Qt runtime, compiled against new version, but old PyQt
|
||||
('5.4.0', '5.4.0', '5.3.0', '5.4.0', False, False),
|
||||
# all up-to-date
|
||||
('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):
|
||||
"""Test for version_check().
|
||||
|
||||
Args:
|
||||
monkeypatch: The pytest monkeypatch fixture.
|
||||
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.
|
||||
exact: Use exact comparing (==)
|
||||
expected: The expected result.
|
||||
@ -74,6 +76,7 @@ def test_version_check(monkeypatch, qversion, compiled, version, exact,
|
||||
monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion)
|
||||
if compiled is not None:
|
||||
monkeypatch.setattr(qtutils, 'QT_VERSION_STR', compiled)
|
||||
monkeypatch.setattr(qtutils, 'PYQT_VERSION_STR', pyqt)
|
||||
compiled_arg = True
|
||||
else:
|
||||
compiled_arg = False
|
||||
|
Loading…
Reference in New Issue
Block a user