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:
parent
8101fe99a8
commit
bffdea6719
@ -276,15 +276,10 @@ def qute_history(url):
|
||||
|
||||
return 'text/html', json.dumps(history_data(start_time))
|
||||
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 (
|
||||
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(
|
||||
'history.html',
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
|
||||
from PyQt5.QtCore import QByteArray, QDataStream, QIODevice, QUrl
|
||||
from PyQt5.QtWebKit import qWebKitVersion
|
||||
|
||||
from qutebrowser.utils import qtutils
|
||||
|
||||
@ -181,7 +180,7 @@ def serialize(items):
|
||||
else:
|
||||
current_idx = 0
|
||||
|
||||
if qtutils.is_qtwebkit_ng(qWebKitVersion()):
|
||||
if qtutils.is_qtwebkit_ng():
|
||||
_serialize_ng(items, current_idx, stream)
|
||||
else:
|
||||
_serialize_old(items, current_idx, stream)
|
||||
|
@ -26,7 +26,7 @@ Module attributes:
|
||||
|
||||
import os.path
|
||||
|
||||
from PyQt5.QtWebKit import QWebSettings, qWebKitVersion
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
|
||||
from qutebrowser.config import config, websettings
|
||||
from qutebrowser.utils import standarddir, objreg, urlutils, qtutils, message
|
||||
@ -90,7 +90,7 @@ def _set_user_stylesheet():
|
||||
|
||||
def _init_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 "
|
||||
"QtWebKit-NG!")
|
||||
QWebSettings.setIconDatabasePath('')
|
||||
|
@ -36,6 +36,10 @@ import contextlib
|
||||
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
|
||||
QIODevice, QSaveFile, QT_VERSION_STR)
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
try:
|
||||
from PyQt5.QtWebKit import qWebKitVersion
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from qutebrowser.utils import log
|
||||
|
||||
@ -100,13 +104,9 @@ def version_check(version, exact=False, strict=False):
|
||||
return result
|
||||
|
||||
|
||||
def is_qtwebkit_ng(version):
|
||||
"""Check if the given version is QtWebKit-NG.
|
||||
|
||||
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) >
|
||||
def is_qtwebkit_ng():
|
||||
"""Check if the given version is QtWebKit-NG."""
|
||||
return (pkg_resources.parse_version(qWebKitVersion()) >
|
||||
pkg_resources.parse_version('538.1'))
|
||||
|
||||
|
||||
|
@ -257,8 +257,7 @@ def _backend():
|
||||
"""Get the backend line with relevant information."""
|
||||
if objects.backend == usertypes.Backend.QtWebKit:
|
||||
return 'QtWebKit{} (WebKit {})'.format(
|
||||
'-NG' if qtutils.is_qtwebkit_ng(qWebKitVersion()) else '',
|
||||
qWebKitVersion())
|
||||
'-NG' if qtutils.is_qtwebkit_ng() else '', qWebKitVersion())
|
||||
else:
|
||||
webengine = usertypes.Backend.QtWebEngine
|
||||
assert objects.backend == webengine, objects.backend
|
||||
|
@ -136,16 +136,6 @@ if not getattr(sys, 'frozen', False):
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
"""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 = [
|
||||
('qtwebengine_todo', 'QtWebEngine TODO', pytest.mark.xfail,
|
||||
config.webengine),
|
||||
@ -154,9 +144,9 @@ def pytest_collection_modifyitems(config, items):
|
||||
('qtwebkit_skip', 'Skipped with QtWebKit', pytest.mark.skipif,
|
||||
not config.webengine),
|
||||
('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_used),
|
||||
not config.webengine and qtutils.is_qtwebkit_ng()),
|
||||
('qtwebengine_flaky', 'Flaky with QtWebEngine', pytest.mark.skipif,
|
||||
config.webengine),
|
||||
('qtwebengine_osx_xfail', 'Fails on OS X with QtWebEngine',
|
||||
|
@ -88,8 +88,9 @@ def test_version_check(monkeypatch, qversion, compiled, version, exact,
|
||||
('538.1', False), # Qt 5.8
|
||||
('602.1', True) # QtWebKit-NG TP5
|
||||
])
|
||||
def test_is_qtwebkit_ng(version, ng):
|
||||
assert qtutils.is_qtwebkit_ng(version) == ng
|
||||
def test_is_qtwebkit_ng(monkeypatch, version, ng):
|
||||
monkeypatch.setattr(qtutils, 'qWebKitVersion', lambda: version)
|
||||
assert qtutils.is_qtwebkit_ng() == ng
|
||||
|
||||
|
||||
class TestCheckOverflow:
|
||||
|
@ -725,13 +725,13 @@ def test_version_output(git_commit, frozen, style, with_webkit, stubs,
|
||||
patches['objects.backend'] = usertypes.Backend.QtWebKit
|
||||
patches['QWebEngineProfile'] = None
|
||||
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)'
|
||||
else:
|
||||
patches['qtutils.is_qtwebkit_ng'] = lambda v: False
|
||||
patches['qtutils.is_qtwebkit_ng'] = lambda: False
|
||||
substitutions['backend'] = 'QtWebKit (WebKit WEBKIT VERSION)'
|
||||
else:
|
||||
patches['qWebKitVersion'] = None
|
||||
monkeypatch.delattr(version, 'qtutils.qWebKitVersion', raising=False)
|
||||
patches['objects.backend'] = usertypes.Backend.QtWebEngine
|
||||
patches['QWebEngineProfile'] = FakeWebEngineProfile
|
||||
substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)'
|
||||
|
Loading…
Reference in New Issue
Block a user