Avoid showing widgets in tests if unneeded
This avoids odd X errors with test_webenginetab.py, and also makes it run much faster (0.8s instead of 1.3s).
This commit is contained in:
parent
e01976277b
commit
f63eb8ea15
@ -54,6 +54,32 @@ from qutebrowser.keyinput import modeman
|
|||||||
_qute_scheme_handler = None
|
_qute_scheme_handler = None
|
||||||
|
|
||||||
|
|
||||||
|
class WidgetContainer(QWidget):
|
||||||
|
|
||||||
|
"""Container for another widget."""
|
||||||
|
|
||||||
|
def __init__(self, qtbot, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self._qtbot = qtbot
|
||||||
|
self.vbox = QVBoxLayout(self)
|
||||||
|
qtbot.add_widget(self)
|
||||||
|
|
||||||
|
def set_widget(self, widget):
|
||||||
|
self.vbox.addWidget(widget)
|
||||||
|
# pylint: disable=attribute-defined-outside-init
|
||||||
|
widget.container = self
|
||||||
|
# pylint: enable=attribute-defined-outside-init
|
||||||
|
|
||||||
|
def expose(self):
|
||||||
|
with self._qtbot.waitExposed(self):
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def widget_container(qtbot):
|
||||||
|
return WidgetContainer(qtbot)
|
||||||
|
|
||||||
|
|
||||||
class WinRegistryHelper:
|
class WinRegistryHelper:
|
||||||
|
|
||||||
"""Helper class for win_registry."""
|
"""Helper class for win_registry."""
|
||||||
@ -100,22 +126,11 @@ class FakeStatusBar(QWidget):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_statusbar(qtbot):
|
def fake_statusbar(widget_container):
|
||||||
"""Fixture providing a statusbar in a container window."""
|
"""Fixture providing a statusbar in a container window."""
|
||||||
container = QWidget()
|
widget_container.vbox.addStretch()
|
||||||
qtbot.add_widget(container)
|
statusbar = FakeStatusBar(widget_container)
|
||||||
vbox = QVBoxLayout(container)
|
widget_container.set_widget(statusbar)
|
||||||
vbox.addStretch()
|
|
||||||
|
|
||||||
statusbar = FakeStatusBar(container)
|
|
||||||
# to make sure container isn't GCed
|
|
||||||
# pylint: disable=attribute-defined-outside-init
|
|
||||||
statusbar.container = container
|
|
||||||
vbox.addWidget(statusbar)
|
|
||||||
# pylint: enable=attribute-defined-outside-init
|
|
||||||
|
|
||||||
with qtbot.waitExposed(container):
|
|
||||||
container.show()
|
|
||||||
return statusbar
|
return statusbar
|
||||||
|
|
||||||
|
|
||||||
@ -190,47 +205,29 @@ def web_tab_setup(qtbot, tab_registry, session_manager_stub,
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def webkit_tab(web_tab_setup, qtbot, cookiejar_and_cache, mode_manager):
|
def webkit_tab(web_tab_setup, qtbot, cookiejar_and_cache, mode_manager,
|
||||||
|
widget_container):
|
||||||
webkittab = pytest.importorskip('qutebrowser.browser.webkit.webkittab')
|
webkittab = pytest.importorskip('qutebrowser.browser.webkit.webkittab')
|
||||||
|
|
||||||
container = QWidget()
|
|
||||||
qtbot.add_widget(container)
|
|
||||||
|
|
||||||
vbox = QVBoxLayout(container)
|
|
||||||
tab = webkittab.WebKitTab(win_id=0, mode_manager=mode_manager,
|
tab = webkittab.WebKitTab(win_id=0, mode_manager=mode_manager,
|
||||||
private=False)
|
private=False)
|
||||||
vbox.addWidget(tab)
|
widget_container.set_widget(tab)
|
||||||
# to make sure container isn't GCed
|
|
||||||
tab.container = container
|
|
||||||
|
|
||||||
with qtbot.waitExposed(container):
|
|
||||||
container.show()
|
|
||||||
|
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def webengine_tab(web_tab_setup, qtbot, redirect_webengine_data,
|
def webengine_tab(web_tab_setup, qtbot, redirect_webengine_data,
|
||||||
tabbed_browser_stubs, mode_manager):
|
tabbed_browser_stubs, mode_manager, widget_container):
|
||||||
tabwidget = tabbed_browser_stubs[0].widget
|
tabwidget = tabbed_browser_stubs[0].widget
|
||||||
tabwidget.current_index = 0
|
tabwidget.current_index = 0
|
||||||
tabwidget.index_of = 0
|
tabwidget.index_of = 0
|
||||||
|
|
||||||
container = QWidget()
|
|
||||||
qtbot.add_widget(container)
|
|
||||||
|
|
||||||
vbox = QVBoxLayout(container)
|
|
||||||
webenginetab = pytest.importorskip(
|
webenginetab = pytest.importorskip(
|
||||||
'qutebrowser.browser.webengine.webenginetab')
|
'qutebrowser.browser.webengine.webenginetab')
|
||||||
|
|
||||||
tab = webenginetab.WebEngineTab(win_id=0, mode_manager=mode_manager,
|
tab = webenginetab.WebEngineTab(win_id=0, mode_manager=mode_manager,
|
||||||
private=False)
|
private=False)
|
||||||
vbox.addWidget(tab)
|
widget_container.set_widget(tab)
|
||||||
# to make sure container isn't GCed
|
|
||||||
tab.container = container
|
|
||||||
|
|
||||||
with qtbot.waitExposed(container):
|
|
||||||
container.show()
|
|
||||||
|
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import textwrap
|
|||||||
import pytest
|
import pytest
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
|
|
||||||
from qutebrowser.utils import usertypes
|
from qutebrowser.utils import usertypes, qtutils
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -331,6 +331,17 @@ class TestFollowSelected:
|
|||||||
def toggle_js(self, request, config_stub):
|
def toggle_js(self, request, config_stub):
|
||||||
config_stub.val.content.javascript.enabled = request.param
|
config_stub.val.content.javascript.enabled = request.param
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def expose(self, web_tab):
|
||||||
|
"""Expose the web view if needed.
|
||||||
|
|
||||||
|
On QtWebKit, or Qt < 5.11 on QtWebEngine, we need to show the tab for
|
||||||
|
selections to work properly.
|
||||||
|
"""
|
||||||
|
if (web_tab.backend == usertypes.Backend.QtWebKit or
|
||||||
|
not qtutils.version_check('5.11', compiled=False)):
|
||||||
|
web_tab.container.expose()
|
||||||
|
|
||||||
def test_follow_selected_without_a_selection(self, qtbot, caret, selection, web_tab,
|
def test_follow_selected_without_a_selection(self, qtbot, caret, selection, web_tab,
|
||||||
mode_manager):
|
mode_manager):
|
||||||
caret.move_to_next_word() # Move cursor away from the link
|
caret.move_to_next_word() # Move cursor away from the link
|
||||||
|
@ -79,6 +79,8 @@ def test_progress_affecting_statusbar_height(config_stub, fake_statusbar,
|
|||||||
# For some reason on Windows, with Courier, there's a 1px difference.
|
# For some reason on Windows, with Courier, there's a 1px difference.
|
||||||
config_stub.val.fonts.statusbar = '8pt Monospace'
|
config_stub.val.fonts.statusbar = '8pt Monospace'
|
||||||
|
|
||||||
|
fake_statusbar.container.expose()
|
||||||
|
|
||||||
expected_height = fake_statusbar.fontMetrics().height()
|
expected_height = fake_statusbar.fontMetrics().height()
|
||||||
assert fake_statusbar.height() == expected_height
|
assert fake_statusbar.height() == expected_height
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user