selectel / pyte

Simple VTXXX-compatible linux terminal emulator
http://pyte.readthedocs.org/
GNU Lesser General Public License v3.0
649 stars 101 forks source link

How to use for testing TUIs? #137

Open yajo opened 3 years ago

yajo commented 3 years ago

Hi there.

I'd love to see an example on how to use this to test a TUI.

Particularly, my project uses https://github.com/tmbo/questionary to ask questions to the user and print a TUI to choose the answers.

I'd love to be able to emulate user interaction, know the messages he's seeing in the screen, emulate some keypress events, read next question, say next answer, etc.

I've been trying to get my head around how to use pyte for this purpose and I'm pretty sure it's possible, but I can't get to how. I'd like something like this pseudocode:

my_process = ['copier', 'copy', src_path, dst_path]
with some_magic_from_pyte(my_process) as input, screen:
    assert 'do_you_love_me?' in screen.display
    input.send('y')
    assert 'your_name?' in screen.display
    input.send('yajo\r')
    assert my_process_did_what_it_had_to_do()

Any help on how to do something similar please? :pray: :innocent:

AlvinKuruvilla commented 2 years ago

I have a similar use case. I would love to use this as part of an automated testing/fuzzing setup