Read qWebKitVersion in qtutils.is_webkit_ng.

This means we need to try and import qWebKitVersion in qtutils, but better there
than at every place which calls it.
This commit is contained in:
Florian Bruhin 2017-04-28 21:36:02 +02:00
parent 8101fe99a8
commit bffdea6719
8 changed files with 21 additions and 37 deletions

View File

@ -276,15 +276,10 @@ def qute_history(url):
return 'text/html', json.dumps(history_data(start_time)) return 'text/html', json.dumps(history_data(start_time))
else: else:
try:
from PyQt5.QtWebKit import qWebKitVersion
is_webkit_ng = qtutils.is_qtwebkit_ng(qWebKitVersion())
except ImportError: # pragma: no cover
is_webkit_ng = False
if ( if (
config.get('content', 'allow-javascript') and config.get('content', 'allow-javascript') and
(objects.backend == usertypes.Backend.QtWebEngine or is_webkit_ng) (objects.backend == usertypes.Backend.QtWebEngine or
qtutils.is_qtwebkit_ng())
): ):
return 'text/html', jinja.render( return 'text/html', jinja.render(
'history.html', 'history.html',

View File

@ -21,7 +21,6 @@
from PyQt5.QtCore import QByteArray, QDataStream, QIODevice, QUrl from PyQt5.QtCore import QByteArray, QDataStream, QIODevice, QUrl
from PyQt5.QtWebKit import qWebKitVersion
from qutebrowser.utils import qtutils from qutebrowser.utils import qtutils
@ -181,7 +180,7 @@ def serialize(items):
else: else:
current_idx = 0 current_idx = 0
if qtutils.is_qtwebkit_ng(qWebKitVersion()): if qtutils.is_qtwebkit_ng():
_serialize_ng(items, current_idx, stream) _serialize_ng(items, current_idx, stream)
else: else:
_serialize_old(items, current_idx, stream) _serialize_old(items, current_idx, stream)

View File

@ -26,7 +26,7 @@ Module attributes:
import os.path import os.path
from PyQt5.QtWebKit import QWebSettings, qWebKitVersion from PyQt5.QtWebKit import QWebSettings
from qutebrowser.config import config, websettings from qutebrowser.config import config, websettings
from qutebrowser.utils import standarddir, objreg, urlutils, qtutils, message from qutebrowser.utils import standarddir, objreg, urlutils, qtutils, message
@ -90,7 +90,7 @@ def _set_user_stylesheet():
def _init_private_browsing(): def _init_private_browsing():
if config.get('general', 'private-browsing'): if config.get('general', 'private-browsing'):
if qtutils.is_qtwebkit_ng(qWebKitVersion()): if qtutils.is_qtwebkit_ng():
message.warning("Private browsing is not fully implemented by " message.warning("Private browsing is not fully implemented by "
"QtWebKit-NG!") "QtWebKit-NG!")
QWebSettings.setIconDatabasePath('') QWebSettings.setIconDatabasePath('')

View File

@ -36,6 +36,10 @@ import contextlib
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)
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
try:
from PyQt5.QtWebKit import qWebKitVersion
except ImportError:
pass
from qutebrowser.utils import log from qutebrowser.utils import log
@ -100,13 +104,9 @@ def version_check(version, exact=False, strict=False):
return result return result
def is_qtwebkit_ng(version): def is_qtwebkit_ng():
"""Check if the given version is QtWebKit-NG. """Check if the given version is QtWebKit-NG."""
return (pkg_resources.parse_version(qWebKitVersion()) >
This is typically used as is_webkit_ng(qWebKitVersion) but we don't want to
have QtWebKit imports in here.
"""
return (pkg_resources.parse_version(version) >
pkg_resources.parse_version('538.1')) pkg_resources.parse_version('538.1'))

View File

@ -257,8 +257,7 @@ def _backend():
"""Get the backend line with relevant information.""" """Get the backend line with relevant information."""
if objects.backend == usertypes.Backend.QtWebKit: if objects.backend == usertypes.Backend.QtWebKit:
return 'QtWebKit{} (WebKit {})'.format( return 'QtWebKit{} (WebKit {})'.format(
'-NG' if qtutils.is_qtwebkit_ng(qWebKitVersion()) else '', '-NG' if qtutils.is_qtwebkit_ng() else '', qWebKitVersion())
qWebKitVersion())
else: else:
webengine = usertypes.Backend.QtWebEngine webengine = usertypes.Backend.QtWebEngine
assert objects.backend == webengine, objects.backend assert objects.backend == webengine, objects.backend

View File

@ -136,16 +136,6 @@ if not getattr(sys, 'frozen', False):
def pytest_collection_modifyitems(config, items): def pytest_collection_modifyitems(config, items):
"""Apply @qtwebengine_* markers; skip unittests with QUTE_BDD_WEBENGINE.""" """Apply @qtwebengine_* markers; skip unittests with QUTE_BDD_WEBENGINE."""
if config.webengine:
qtwebkit_ng_used = False
else:
try:
from PyQt5.QtWebKit import qWebKitVersion
except ImportError:
qtwebkit_ng_used = False
else:
qtwebkit_ng_used = qtutils.is_qtwebkit_ng(qWebKitVersion())
markers = [ markers = [
('qtwebengine_todo', 'QtWebEngine TODO', pytest.mark.xfail, ('qtwebengine_todo', 'QtWebEngine TODO', pytest.mark.xfail,
config.webengine), config.webengine),
@ -154,9 +144,9 @@ def pytest_collection_modifyitems(config, items):
('qtwebkit_skip', 'Skipped with QtWebKit', pytest.mark.skipif, ('qtwebkit_skip', 'Skipped with QtWebKit', pytest.mark.skipif,
not config.webengine), not config.webengine),
('qtwebkit_ng_xfail', 'Failing with QtWebKit-NG', pytest.mark.xfail, ('qtwebkit_ng_xfail', 'Failing with QtWebKit-NG', pytest.mark.xfail,
qtwebkit_ng_used), not config.webengine and qtutils.is_qtwebkit_ng()),
('qtwebkit_ng_skip', 'Skipped with QtWebKit-NG', pytest.mark.skipif, ('qtwebkit_ng_skip', 'Skipped with QtWebKit-NG', pytest.mark.skipif,
qtwebkit_ng_used), not config.webengine and qtutils.is_qtwebkit_ng()),
('qtwebengine_flaky', 'Flaky with QtWebEngine', pytest.mark.skipif, ('qtwebengine_flaky', 'Flaky with QtWebEngine', pytest.mark.skipif,
config.webengine), config.webengine),
('qtwebengine_osx_xfail', 'Fails on OS X with QtWebEngine', ('qtwebengine_osx_xfail', 'Fails on OS X with QtWebEngine',

View File

@ -88,8 +88,9 @@ def test_version_check(monkeypatch, qversion, compiled, version, exact,
('538.1', False), # Qt 5.8 ('538.1', False), # Qt 5.8
('602.1', True) # QtWebKit-NG TP5 ('602.1', True) # QtWebKit-NG TP5
]) ])
def test_is_qtwebkit_ng(version, ng): def test_is_qtwebkit_ng(monkeypatch, version, ng):
assert qtutils.is_qtwebkit_ng(version) == ng monkeypatch.setattr(qtutils, 'qWebKitVersion', lambda: version)
assert qtutils.is_qtwebkit_ng() == ng
class TestCheckOverflow: class TestCheckOverflow:

View File

@ -725,13 +725,13 @@ def test_version_output(git_commit, frozen, style, with_webkit, stubs,
patches['objects.backend'] = usertypes.Backend.QtWebKit patches['objects.backend'] = usertypes.Backend.QtWebKit
patches['QWebEngineProfile'] = None patches['QWebEngineProfile'] = None
if with_webkit == 'ng': if with_webkit == 'ng':
patches['qtutils.is_qtwebkit_ng'] = lambda v: True patches['qtutils.is_qtwebkit_ng'] = lambda: True
substitutions['backend'] = 'QtWebKit-NG (WebKit WEBKIT VERSION)' substitutions['backend'] = 'QtWebKit-NG (WebKit WEBKIT VERSION)'
else: else:
patches['qtutils.is_qtwebkit_ng'] = lambda v: False patches['qtutils.is_qtwebkit_ng'] = lambda: False
substitutions['backend'] = 'QtWebKit (WebKit WEBKIT VERSION)' substitutions['backend'] = 'QtWebKit (WebKit WEBKIT VERSION)'
else: else:
patches['qWebKitVersion'] = None monkeypatch.delattr(version, 'qtutils.qWebKitVersion', raising=False)
patches['objects.backend'] = usertypes.Backend.QtWebEngine patches['objects.backend'] = usertypes.Backend.QtWebEngine
patches['QWebEngineProfile'] = FakeWebEngineProfile patches['QWebEngineProfile'] = FakeWebEngineProfile
substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)' substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)'