100% coverage for mainwindow/statusbar/prompt.py.

This commit is contained in:
Florian Bruhin 2016-01-11 07:14:51 +01:00
parent 5ddc94bc8d
commit 70cd18fc98
4 changed files with 96 additions and 41 deletions

View File

@ -100,6 +100,8 @@ PERFECT_FILES = [
'qutebrowser/mainwindow/statusbar/tabindex.py'),
('tests/unit/mainwindow/statusbar/test_textbase.py',
'qutebrowser/mainwindow/statusbar/textbase.py'),
('tests/unit/mainwindow/statusbar/test_prompt.py',
'qutebrowser/mainwindow/statusbar/prompt.py'),
('tests/unit/config/test_configtypes.py',
'qutebrowser/config/configtypes.py'),
@ -134,9 +136,7 @@ PERFECT_FILES = [
# 100% coverage because of integration tests, but no perfect unit tests yet.
WHITELISTED_FILES = [
'qutebrowser/mainwindow/statusbar/prompt.py'
]
WHITELISTED_FILES = []
class Skipped(Exception):

View File

@ -39,7 +39,8 @@ from helpers.messagemock import message_mock
from qutebrowser.config import config
from qutebrowser.utils import objreg
from PyQt5.QtCore import QEvent
from PyQt5.QtCore import QEvent, QSize, Qt
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
from PyQt5.QtNetwork import QNetworkCookieJar
import xvfbwrapper
@ -164,6 +165,41 @@ class WinRegistryHelper:
del objreg.window_registry[win_id]
class FakeStatusBar(QWidget):
"""Fake statusbar to test progressbar sizing."""
def __init__(self, parent=None):
super().__init__(parent)
self.hbox = QHBoxLayout(self)
self.hbox.addStretch()
self.hbox.setContentsMargins(0, 0, 0, 0)
self.setAttribute(Qt.WA_StyledBackground, True)
self.setStyleSheet('background-color: red;')
def minimumSizeHint(self):
return QSize(1, self.fontMetrics().height())
@pytest.fixture
def fake_statusbar(qtbot):
"""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)
container.show()
qtbot.waitForWindowShown(container)
return statusbar
@pytest.yield_fixture
def win_registry():
"""Fixture providing a window registry for win_id 0 and 1."""

View File

@ -23,29 +23,11 @@
from collections import namedtuple
import pytest
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
from PyQt5.QtCore import QSize, Qt
from qutebrowser.browser import webview
from qutebrowser.mainwindow.statusbar.progress import Progress
class FakeStatusBar(QWidget):
"""Fake statusbar to test progressbar sizing."""
def __init__(self, parent=None):
super().__init__(parent)
self.hbox = QHBoxLayout(self)
self.hbox.addStretch()
self.hbox.setContentsMargins(0, 0, 0, 0)
self.setAttribute(Qt.WA_StyledBackground, True)
self.setStyleSheet('background-color: red;')
def minimumSizeHint(self):
return QSize(1, self.fontMetrics().height())
@pytest.fixture
def progress_widget(qtbot, monkeypatch, config_stub):
"""Create a Progress widget and checks its initial state."""
@ -62,25 +44,6 @@ def progress_widget(qtbot, monkeypatch, config_stub):
return widget
@pytest.fixture
def fake_statusbar(qtbot):
"""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)
container.show()
qtbot.waitForWindowShown(container)
return statusbar
def test_load_started(progress_widget):
"""Ensure the Progress widget reacts properly when the page starts loading.

View File

@ -0,0 +1,56 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Test Prompt widget."""
import pytest
from qutebrowser.mainwindow.statusbar.prompt import Prompt
from qutebrowser.utils import objreg
@pytest.yield_fixture
def prompt(qtbot, win_registry):
prompt = Prompt(0)
qtbot.addWidget(prompt)
yield prompt
# If we don't clean up here, this test will remove 'prompter' from the
# objreg at some point in the future, which will cause some other test to
# fail.
with qtbot.waitSignal(prompt.destroyed):
prompt.deleteLater()
def test_prompt(prompt):
prompt.show()
objreg.get('prompt', scope='window', window=0)
objreg.get('prompter', scope='window', window=0)
@pytest.mark.xfail(reason="This test is broken and I don't get why")
def test_resizing(fake_statusbar, prompt):
fake_statusbar.hbox.addWidget(prompt)
prompt.txt.setText("Blah?")
old_width = prompt.lineedit.width()
prompt.lineedit.setText("Hello World" * 100)
assert prompt.lineedit.width() > old_width