summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2018-10-06 19:04:28 +0200
committerFlorian Bruhin <me@the-compiler.org>2018-10-06 19:06:34 +0200
commitf63eb8ea15335dd34ee5403332dec39dacdf0f7b (patch)
treec70306b91003d0e8e04e0f2ed53572997f9750c6
parente01976277bffb7e0b310f49faa40f9847cf5a03d (diff)
downloadqutebrowser-f63eb8ea15335dd34ee5403332dec39dacdf0f7b.tar.gz
qutebrowser-f63eb8ea15335dd34ee5403332dec39dacdf0f7b.zip
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).
-rw-r--r--tests/helpers/fixtures.py75
-rw-r--r--tests/unit/browser/test_caret.py13
-rw-r--r--tests/unit/mainwindow/statusbar/test_progress.py2
3 files changed, 50 insertions, 40 deletions
diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py
index 13a0cc970..5a32575ca 100644
--- a/tests/helpers/fixtures.py
+++ b/tests/helpers/fixtures.py
@@ -54,6 +54,32 @@ from qutebrowser.keyinput import modeman
_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:
"""Helper class for win_registry."""
@@ -100,22 +126,11 @@ class FakeStatusBar(QWidget):
@pytest.fixture
-def fake_statusbar(qtbot):
+def fake_statusbar(widget_container):
"""Fixture providing a statusbar in a container window."""
- container = QWidget()
- qtbot.add_widget(container)
- vbox = QVBoxLayout(container)
- 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()
+ widget_container.vbox.addStretch()
+ statusbar = FakeStatusBar(widget_container)
+ widget_container.set_widget(statusbar)
return statusbar
@@ -190,47 +205,29 @@ def web_tab_setup(qtbot, tab_registry, session_manager_stub,
@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')
- container = QWidget()
- qtbot.add_widget(container)
-
- vbox = QVBoxLayout(container)
tab = webkittab.WebKitTab(win_id=0, mode_manager=mode_manager,
private=False)
- vbox.addWidget(tab)
- # to make sure container isn't GCed
- tab.container = container
-
- with qtbot.waitExposed(container):
- container.show()
-
+ widget_container.set_widget(tab)
return tab
@pytest.fixture
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.current_index = 0
tabwidget.index_of = 0
- container = QWidget()
- qtbot.add_widget(container)
-
- vbox = QVBoxLayout(container)
webenginetab = pytest.importorskip(
'qutebrowser.browser.webengine.webenginetab')
+
tab = webenginetab.WebEngineTab(win_id=0, mode_manager=mode_manager,
private=False)
- vbox.addWidget(tab)
- # to make sure container isn't GCed
- tab.container = container
-
- with qtbot.waitExposed(container):
- container.show()
-
+ widget_container.set_widget(tab)
return tab
diff --git a/tests/unit/browser/test_caret.py b/tests/unit/browser/test_caret.py
index 27b421c84..6165546e5 100644
--- a/tests/unit/browser/test_caret.py
+++ b/tests/unit/browser/test_caret.py
@@ -24,7 +24,7 @@ import textwrap
import pytest
from PyQt5.QtCore import QUrl
-from qutebrowser.utils import usertypes
+from qutebrowser.utils import usertypes, qtutils
@pytest.fixture
@@ -331,6 +331,17 @@ class TestFollowSelected:
def toggle_js(self, request, config_stub):
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,
mode_manager):
caret.move_to_next_word() # Move cursor away from the link
diff --git a/tests/unit/mainwindow/statusbar/test_progress.py b/tests/unit/mainwindow/statusbar/test_progress.py
index 6d054a5c9..5b01aebbf 100644
--- a/tests/unit/mainwindow/statusbar/test_progress.py
+++ b/tests/unit/mainwindow/statusbar/test_progress.py
@@ -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.
config_stub.val.fonts.statusbar = '8pt Monospace'
+ fake_statusbar.container.expose()
+
expected_height = fake_statusbar.fontMetrics().height()
assert fake_statusbar.height() == expected_height