You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using InquirerPy in a small project to build the user interface ther. The project involves some non-trivial validators and workflows and I would like to ensure that these work by writing a unit test that mimics some key presses and checks the result somehow.
I am aware of this FAQ entry but find it not satisfactory. It resorts to mock InquirerPy to receive the correct answer, but it is exactly the process of getting the right answer I want to test. For instance, I might want to restructure the questions list. Maybe I want to refactor the validators. Whether these cases work or not cannot be tested by mocking InquirerPy.
I tried to look up how prompt-toolkit does it. Unfortunately this causes the tests to hang badly. I need to pkill pytest to shut down the test suite. Please find a MWE attached.
Could you please explain how I could test my workflows?
from typing import Any
from InquirerPy.resolver import prompt
from prompt_toolkit.application import create_app_session
from prompt_toolkit.input import create_pipe_input
from prompt_toolkit.output import DummyOutput
def test_something():
questions: list[dict[str, Any]] = [
{
"type": "expand",
"name": "command",
"message": "Please press 'q'!",
"default": "s",
"choices": [
{"key": "q", "name": "Quit Program", "value": "quit"},
],
},
{
"type": "confirm",
"name": "confirmation",
"message": "Press 'y' to confirm!",
"when": lambda answers: answers["command"] in {"delete", "quit"},
"default": False,
},
]
with create_pipe_input() as pipe_input:
pipe_input.send_text("q\ny\n")
with create_app_session(input=pipe_input, output=DummyOutput()):
prompt(questions)
The text was updated successfully, but these errors were encountered:
I am using InquirerPy in a small project to build the user interface ther. The project involves some non-trivial validators and workflows and I would like to ensure that these work by writing a unit test that mimics some key presses and checks the result somehow.
I am aware of this FAQ entry but find it not satisfactory. It resorts to mock InquirerPy to receive the correct answer, but it is exactly the process of getting the right answer I want to test. For instance, I might want to restructure the questions list. Maybe I want to refactor the validators. Whether these cases work or not cannot be tested by mocking InquirerPy.
I tried to look up how
prompt-toolkit
does it. Unfortunately this causes the tests to hang badly. I need topkill pytest
to shut down the test suite. Please find a MWE attached.Could you please explain how I could test my workflows?
The text was updated successfully, but these errors were encountered: