Python ncurses testing

I am developing a terminal application. And I am wondering how you can test the terminal user interface made using ncurses. Does anyone have experience with such testing?

  • So far, my best hit would be to test the application with the stdout capture and compare it with what it should be. But I am worried that I could never create a comparable case for each terminal size, text colors for codes (256 bits, 24 bits), etc.

  • One way to test is to simulate a keyboard, but how can I test the visual behavior?

I don’t know what the problem is ...

+7
python ncurses
source share
2 answers

Comparing screen output is difficult because ncurses only updates the changed parts of the screen using cursor addressing and other methods. Instead, the best approach is to compare the contents of a screen known as ncurses at different points in time.

You can create a dump screen using instr to get the text (but this omits attributes like color). The Python interface for ncurses also has inch (but it is assumed that the characters are 8 bits)

It would be nice to use putwin , but this (until recently) kept the window in binary form. The upcoming ncurses6 uses a text dump , which can be difficult. This change is not displayed to callers (since putwin / getwin always treated the file format as secret), and in principle, it can be included in the ncurse5 assembly. To do this, you probably have to create your own ncurses.

+1
source share

The program that you probably want to test is a TCL script called Expect . It is designed to automate text-based interaction.

On Wikipedia:

[Expect] is used to automate the management of interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh and others. Expect uses pseudo-terminals (Unix) or emulates a console (Windows), launches the target program and then communicates with it, like a person, through the interface of a terminal or console.

I assume that you can configure the Expect script to run standard interaction and report any interaction problems along the way.

I doubt that any program can test aesthetics (that is, how it looks to the eye, etc.), but you can probably check if the interface is suitable on the screen and that different windows do not overlap, etc. adding a decorator to PyCurses function calls that track the sizes of various parts and report any overlaps or problems.

Read more about Python decorators in this article: Understanding Python Decorators in 12 Easy Steps!

+1
source share

All Articles