IngoMeyer441 / simple-term-menu

A Python package which creates simple interactive menus on the command line.
MIT License
492 stars 43 forks source link

Writing tests for menu interaction? #56

Open gamesbook opened 2 years ago

gamesbook commented 2 years ago

Are there any guidelines for how to use pytest to interact with a "live" menu and validate it handles and processes all items?

IngoMeyer441 commented 2 years ago

This is a topic I am actually also interested in. Until now, I don't know how to do this because of the interactive part of the menu and the stream of text with control characters which is written.

gamesbook commented 2 years ago

Is there no way for a test to simulate passing a menu choice to the menu "function" and checking that the right menu item is called? SO suggests using a monkeypatch for this - https://stackoverflow.com/questions/35851323/how-to-test-a-function-with-input-call

IngoMeyer441 commented 2 years ago

Ok, this is already a good point. But I think we also need a kind of terminal emulator to check if the generated output escape sequences cause the right menu display. We need something like Selenium, but for a terminal application. After a quick search, I could not find anything like this (yet).

gamesbook commented 2 years ago

https://twitter.com/willmcgugan is working on rich and textual which are libraries heavily focused on console/terminal applications. He might have some ideas/approaches for testing.

AlvinKuruvilla commented 2 years ago

I'm also working on a TUI application, and I was wondering about a similar thing. I wanted to provide arbitrary input to generate fizz cases for my application. The closest I got was using subprocess and trying o send strings to it through stdin. I also just found these 2 resources that could potentially be a starting point https://www.youtube.com/watch?v=1aVe7bny5_Y https://stackoverflow.com/questions/70947472/how-can-i-send-keystrokes-and-mouse-movement-to-a-specific-pid