File: test_prompt.py

package info (click to toggle)
python-questionary 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 960 kB
  • sloc: python: 3,917; makefile: 66
file content (78 lines) | stat: -rw-r--r-- 2,070 bytes parent folder | download | duplicates (2)
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
import pytest

from questionary.prompt import PromptParameterException
from questionary.prompt import prompt
from tests.utils import patched_prompt


def test_missing_message():
    with pytest.raises(PromptParameterException):
        prompt([{"type": "confirm", "name": "continue", "default": True}])


def test_missing_type():
    with pytest.raises(PromptParameterException):
        prompt(
            [
                {
                    "message": "Do you want to continue?",
                    "name": "continue",
                    "default": True,
                }
            ]
        )


def test_missing_name():
    with pytest.raises(PromptParameterException):
        prompt(
            [
                {
                    "type": "confirm",
                    "message": "Do you want to continue?",
                    "default": True,
                }
            ]
        )


def test_invalid_question_type():
    with pytest.raises(ValueError):
        prompt(
            [
                {
                    "type": "mytype",
                    "message": "Do you want to continue?",
                    "name": "continue",
                    "default": True,
                }
            ]
        )


def test_missing_print_message():
    """Test 'print' raises exception if missing 'message'"""
    with pytest.raises(PromptParameterException):
        prompt(
            [
                {
                    "name": "test",
                    "type": "print",
                }
            ]
        )


def test_print_no_name():
    """'print' type doesn't require a name so it
    should not throw PromptParameterException"""
    questions = [{"type": "print", "message": "Hello World"}]
    result = patched_prompt(questions, "")
    assert result == {}


def test_print_with_name():
    """'print' type should return {name: None} when name is provided"""
    questions = [{"name": "hello", "type": "print", "message": "Hello World"}]
    result = patched_prompt(questions, "")
    assert result == {"hello": None}