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 example_form(inp):
return form(
q1=questionary.confirm("Hello?", input=inp, output=DummyOutput()),
q2=questionary.select(
"World?", choices=["foo", "bar"], input=inp, output=DummyOutput()
),
def test_to_many_choices_for_shortcut_assignment():
ic = InquirerControl([str(i) for i in range(1, 100)], use_shortcuts=True)
# IC should fail gracefully when running out of shortcuts
assert len(list(filter(lambda x: x.shortcut_key is not None, ic.choices))) == len(
InquirerControl.SHORTCUT_KEYS
)
def test_blank_line_fix():
def get_prompt_tokens():
return [("class:question", "What is your favourite letter?")]
ic = InquirerControl(["a", "b", "c"])
inp = create_pipe_input()
try:
inp.send_text("")
layout = common.create_inquirer_layout(
ic, get_prompt_tokens, input=inp, output=DummyOutput()
)
# usually this would be 2000000000000000000000000000000
# but `common._fix_unecessary_blank_lines` makes sure
# the main window is not as greedy (avoiding blank lines)
assert (
layout.container.preferred_height(100, 200).max
== 1000000000000000000000000000001
)