summaryrefslogtreecommitdiff
path: root/tests/unit/utils/usertypes/test_question.py
blob: 5e37311093569bdb17e2be1157a1530b0a9ae555 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:

# Copyright 2015-2021 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 <https://www.gnu.org/licenses/>.

"""Tests for usertypes.Question."""

import pytest

from qutebrowser.utils import usertypes


@pytest.fixture
def question():
    return usertypes.Question()


def test_attributes(question):
    """Test setting attributes."""
    question.default = True
    question.text = "foo"


def test_mode(question):
    """Test setting mode to valid members."""
    question.mode = usertypes.PromptMode.yesno
    assert question.mode == usertypes.PromptMode.yesno


@pytest.mark.parametrize('mode, answer, signal_names', [
    (usertypes.PromptMode.text, 'foo', ['answered', 'completed']),
    (usertypes.PromptMode.yesno, True, ['answered', 'answered_yes',
                                        'completed']),
    (usertypes.PromptMode.yesno, False, ['answered', 'answered_no',
                                         'completed']),
])
def test_done(mode, answer, signal_names, question, qtbot):
    """Test the 'done' method and completed/answered signals."""
    question.mode = mode
    question.answer = answer
    signals = [getattr(question, name) for name in signal_names]
    with qtbot.wait_signals(signals, order='strict'):
        question.done()
    assert not question.is_aborted


def test_cancel(question, qtbot):
    """Test Question.cancel()."""
    with qtbot.wait_signals([question.cancelled, question.completed],
                           order='strict'):
        question.cancel()
    assert not question.is_aborted


def test_abort(question, qtbot):
    """Test Question.abort()."""
    with qtbot.wait_signals([question.aborted, question.completed],
                           order='strict'):
        question.abort()
    assert question.is_aborted


def test_abort_twice(question, qtbot):
    """Abort a question twice."""
    with qtbot.wait_signal(question.aborted):
        question.abort()
    assert question.is_aborted
    with qtbot.assert_not_emitted(question.aborted):
        question.abort()