Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_select_all_deselect():
message = "Foo message"
kwargs = {
"choices": [
{"name": "foo", "checked": True},
Separator(),
{"name": "bar", "disabled": "nope"},
"bazz",
Separator("--END--"),
]
}
text = KeyInputs.UP + "a" + "a" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == []
def test_select_all():
message = "Foo message"
kwargs = {
"choices": [
{"name": "foo", "checked": True},
Separator(),
{"name": "bar", "disabled": "nope"},
"bazz",
Separator("--END--"),
]
}
text = KeyInputs.UP + "a" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == ["foo", "bazz"]
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_select_invert():
message = "Foo message"
kwargs = {
"choices": [
{"name": "foo", "checked": True},
Separator(),
{"name": "bar", "disabled": "nope"},
"bazz",
Separator("--END--"),
]
}
text = KeyInputs.UP + "i" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == ["bazz"]
def test_separator_up():
message = "Foo message"
kwargs = {"choices": ["foo", Separator(), "bazz", Separator("--END--")]}
text = KeyInputs.UP + KeyInputs.UP + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("select", message, text, **kwargs)
assert result == "foo"
def test_select_all():
message = "Foo message"
kwargs = {
"choices": [
{"name": "foo", "checked": True},
Separator(),
{"name": "bar", "disabled": "nope"},
"bazz",
Separator("--END--"),
]
}
text = KeyInputs.UP + "a" + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == ["foo", "bazz"]
def test_separator_down():
message = "Foo message"
kwargs = {"choices": ["foo", Separator(), "bazz"]}
text = KeyInputs.DOWN + KeyInputs.SPACE + KeyInputs.ENTER + "\r"
result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == ["bazz"]
def ask_pystyle(**kwargs):
# create the question object
question = questionary.select(
"What do you want to do?",
qmark="😃",
choices=[
"Order a pizza",
"Make a reservation",
Separator(),
"Ask for opening hours",
Choice("Contact support", disabled="Unavailable at this time"),
"Talk to the receptionist",
],
style=custom_style_dope,
**kwargs,
)
# prompt the user for an answer
return question.ask()
def ask_pystyle(**kwargs):
# create the question object
question = questionary.checkbox(
"Select toppings",
qmark="😃",
choices=[
Choice("foo", checked=True),
Separator(),
Choice("bar", disabled="nope"),
"bazz",
Separator("--END--"),
],
style=custom_style_dope,
**kwargs,
)
# prompt the user for an answer
return question.ask()