Reputation: 3876
I am writing an interactive terminal program using Python curses. I'd like to write unit tests for its functionalities such as drawing custom pads, controlling font colors, scrolling, and resizing responses. But after some tries and searches, I couldn't find a way to write such unit tests without actually invoking the terminal; I couldn't find a function in curses to read the content of the screen, either.
Is there a mock terminal for Python curses that serves these unit testing needs?
Upvotes: 1
Views: 808
Reputation: 54563
You can ask curses what it thinks is on the screen:
The Python binding provides a way to use those functions (not complete, but sufficient):
Return the character at the given position in the window. The bottom 8 bits are the character proper, and upper bits are the attributes.
Return a string of characters, extracted from the window starting at the current cursor position, or at y, x if specified. Attributes are stripped from the characters. If n is specified, instr() returns a string at most n characters long (exclusive of the trailing NUL).
Upvotes: 2