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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
# -*- coding: utf-8 -*-
import uuid
import pytest
from questionary import Separator
from tests.utils import KeyInputs
from tests.utils import feed_cli_with_input
def test_legacy_name():
message = "Foo message"
kwargs = {"choices": ["foo", "bar", "bazz"]}
text = "1" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("rawlist", message, text, **kwargs)
assert result == "foo"
def test_select_first_choice():
message = "Foo message"
kwargs = {"choices": ["foo", "bar", "bazz"]}
text = "1" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("rawselect", message, text, **kwargs)
assert result == "foo"
def test_select_second_choice():
message = "Foo message"
kwargs = {"choices": ["foo", "bar", "bazz"]}
text = "2" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("rawselect", message, text, **kwargs)
assert result == "bar"
def test_select_third_choice():
message = "Foo message"
kwargs = {"choices": ["foo", "bar", "bazz"]}
text = "2" + "3" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("rawselect", message, text, **kwargs)
assert result == "bazz"
def test_separator_shortcuts():
message = "Foo message"
kwargs = {"choices": ["foo", Separator(), "bazz"]}
text = "2" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("rawselect", message, text, **kwargs)
assert result == "bazz"
def test_duplicated_shortcuts():
message = "Foo message"
kwargs = {
"choices": [
{"name": "foo", "key": 1},
Separator(),
{"name": "bar", "key": 1},
"bazz",
Separator("--END--"),
]
}
text = "1" + KeyInputs.ENTER + "\r"
with pytest.raises(ValueError):
feed_cli_with_input("rawselect", message, text, **kwargs)
def test_invalid_shortcuts():
message = "Foo message"
kwargs = {
"choices": [
{"name": "foo", "key": "asd"},
Separator(),
{"name": "bar", "key": "1"},
"bazz",
Separator("--END--"),
]
}
text = "1" + KeyInputs.ENTER + "\r"
with pytest.raises(ValueError):
feed_cli_with_input("rawselect", message, text, **kwargs)
def test_to_many_choices():
message = "Foo message"
kwargs = {"choices": [uuid.uuid4().hex for _ in range(0, 37)]}
text = "1" + KeyInputs.ENTER + "\r"
with pytest.raises(ValueError):
feed_cli_with_input("rawselect", message, text, **kwargs)
def test_select_random_input():
message = "Foo message"
kwargs = {"choices": ["foo", "bazz"]}
text = "2" + "some random input" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("rawselect", message, text, **kwargs)
assert result == "bazz"
def test_select_ctr_c():
message = "Foo message"
kwargs = {"choices": ["foo", "bazz"]}
text = KeyInputs.CONTROLC
with pytest.raises(KeyboardInterrupt):
feed_cli_with_input("rawselect", message, text, **kwargs)
|