add a test for the new prompt option

This commit is contained in:
Grant Ramsay 2023-06-30 20:10:10 +01:00
parent 895464fee9
commit 8de138ea6a
No known key found for this signature in database
GPG key ID: 40EDDC3F71696632

View file

@ -1,7 +1,7 @@
import io
from rich.console import Console
from rich.prompt import Prompt, IntPrompt, Confirm
from rich.prompt import Confirm, IntPrompt, Prompt
def test_prompt_str():
@ -21,6 +21,24 @@ def test_prompt_str():
assert output == expected
def test_prompt_str_case_insensitive():
INPUT = "egg\nFoO"
console = Console(file=io.StringIO())
name = Prompt.ask(
"what is your name",
console=console,
choices=["foo", "bar"],
default="baz",
case_insensitive=True,
stream=io.StringIO(INPUT),
)
assert name == "foo"
expected = "what is your name [foo/bar] (baz): Please select one of the available options\nwhat is your name [foo/bar] (baz): "
output = console.file.getvalue()
print(repr(output))
assert output == expected
def test_prompt_str_default():
INPUT = ""
console = Console(file=io.StringIO())