-
Notifications
You must be signed in to change notification settings - Fork 725
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
how to test? #1243
Comments
I think in the most recent versions, the easiest to do it is like this: from prompt_toolkit.input import create_pipe_input
from prompt_toolkit.application import AppSession, create_app_session
from prompt_toolkit.output import DummyOutput
input = create_pipe_input() # Create an alternative input device, similar to StringIO.
input.send_text("hello\n")
with create_app_session(input=input, output=DummyOutput()):
# run your application here. It will by default take the input/output objects from the AppSession. If this works and is useful to you, feel free to add it to the documentation. |
OK, let me test that. Thanks! |
It seems to be working, although I cannot find a way to assert what is printed in the user screen. There's no |
Finally I decided to test using https://github.com/pexpect/pexpect, which works great on Linux/mac because it uses a TTy and lets you interact with it and check what's happening. However,
Thus my new question is: is there any way to circumvent that requirement of running under Note 1: there's https://github.com/raczben/wexpect for Windows, but it has several issues such as raczben/wexpect#42, raczben/wexpect#39, raczben/wexpect#26 and raczben/wexpect#22 that make it not very useful at the moment. Note 2: I know it's not "your business" to make this work with |
@yajo This can be achieved like so: Extending @jonathanslenders 's example: from io import StringIO
from prompt_toolkit.application import create_app_session
from prompt_toolkit.input import create_pipe_input
from prompt_toolkit.output import create_output
input = create_pipe_input() # Create an alternative input device, similar to StringIO.
input.send_text("hello\n")
buffer = StringIO() # Use to capture stdout
with create_app_session(
input=input,
output=create_output(stdout=buffer),
):
# run your application here. It will by default take the input/output objects from the AppSession.
buffer.seek(0)
output = buffer.read() |
is >>> from prompt_toolkit.input import create_pipe_input
>>> input_pipe = create_pipe_input()
>>> input_pipe.send_text("test")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: '_GeneratorContextManager' object has no attribute 'send_text'
>>> EDIT: nvm found it, phew - so this changed to return context manager I see. Does that means that |
Is there a way to programatically check boxes in a dialog with multiple check boxes created with checkboxlist_dialog()? |
I've been trying to use this library but it breaks my tests.
I build a CLI app that asks for some questions to the user. Some uni t tests emulate some content in the STDIN to check the user interaction works as expected. But doing it with thi s library fails.
How are we supposed to test user interactions when using this library? I don't find that on the docs.
The text was updated successfully, but these errors were encountered: