100% coverage for misc.msgbox.
This commit is contained in:
parent
9892c10f49
commit
5d013a67a7
@ -47,6 +47,7 @@ PERFECT_FILES = [
|
||||
|
||||
'qutebrowser/misc/readline.py',
|
||||
'qutebrowser/misc/split.py',
|
||||
'qutebrowser/misc/msgbox.py',
|
||||
|
||||
'qutebrowser/mainwindow/statusbar/keystring.py',
|
||||
'qutebrowser/mainwindow/statusbar/percentage.py',
|
||||
|
85
tests/misc/test_msgbox.py
Normal file
85
tests/misc/test_msgbox.py
Normal file
@ -0,0 +1,85 @@
|
||||
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# 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/>.
|
||||
|
||||
"""Tests for qutebrowser.misc.msgbox."""
|
||||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.misc import msgbox
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QWidget
|
||||
|
||||
|
||||
def test_attributes(qtbot):
|
||||
"""Test basic QMessageBox attributes."""
|
||||
title = 'title'
|
||||
text = 'text'
|
||||
parent = QWidget()
|
||||
qtbot.add_widget(parent)
|
||||
icon = QMessageBox.Critical
|
||||
buttons = QMessageBox.Ok | QMessageBox.Cancel
|
||||
|
||||
box = msgbox.msgbox(parent=parent, title=title, text=text, icon=icon,
|
||||
buttons=buttons)
|
||||
qtbot.add_widget(box)
|
||||
assert box.windowTitle() == title
|
||||
assert box.icon() == icon
|
||||
assert box.standardButtons() == buttons
|
||||
assert box.text() == text
|
||||
assert box.parent() is parent
|
||||
|
||||
|
||||
@pytest.mark.parametrize('plain_text, expected', [
|
||||
(True, Qt.PlainText),
|
||||
(False, Qt.RichText),
|
||||
(None, Qt.AutoText),
|
||||
])
|
||||
def test_plain_text(qtbot, plain_text, expected):
|
||||
box = msgbox.msgbox(parent=None, title='foo', text='foo',
|
||||
icon=QMessageBox.Information, plain_text=plain_text)
|
||||
qtbot.add_widget(box)
|
||||
assert box.textFormat() == expected
|
||||
|
||||
|
||||
def test_finished_signal(qtbot):
|
||||
"""Make sure we can pass a slot to be called when the dialog finished."""
|
||||
signal_triggered = False
|
||||
|
||||
@pyqtSlot()
|
||||
def on_finished():
|
||||
nonlocal signal_triggered
|
||||
signal_triggered = True
|
||||
|
||||
box = msgbox.msgbox(parent=None, title='foo', text='foo',
|
||||
icon=QMessageBox.Information, on_finished=on_finished)
|
||||
|
||||
qtbot.add_widget(box)
|
||||
|
||||
with qtbot.waitSignal(box.finished, raising=True):
|
||||
box.accept()
|
||||
|
||||
assert signal_triggered
|
||||
|
||||
|
||||
def test_information(qtbot):
|
||||
box = msgbox.information(parent=None, title='foo', text='bar')
|
||||
qtbot.add_widget(box)
|
||||
assert box.windowTitle() == 'foo'
|
||||
assert box.text() == 'bar'
|
||||
assert box.icon() == QMessageBox.Information
|
Loading…
Reference in New Issue
Block a user