Python 测试 ncurses

Python testing ncurses

我正在开发终端应用程序。我想知道一个人怎么能 测试用 ncurses 制作的终端用户界面。有人对这种测试有经验吗?

我对这个问题一无所知...

比较屏幕输出很困难,因为 ncurses 使用光标寻址和其他方法仅更新屏幕的更改部分。相反,比较 ncurses 在不同时间点已知的屏幕内容是最好的方法。

您可以使用 instr to get the text (but that omits attributes such as color). The Python interface to ncurses also has inch 构建屏幕转储(但假设字符是 8 位)

最好使用 putwin, but that (until recently) saves the window in binary form. Upcoming ncurses6 uses a text dump,这可能会有所不同。调用者看不到更改(因为 putwin/getwin 始终将文件格式视为秘密),并且原则上可以在 ncurse5 的构建中打开。为此,您可能必须构建自己的 ncurses。

您可能想要查看的程序是一个名为 Expect 的 TCL 脚本。它旨在自动化基于文本的交互。

根据维基百科:

[Expect] is used to automate control of interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. Expect uses pseudo terminals (Unix) or emulates a console (Windows), starts the target program, and then communicates with it, just as a human would, via the terminal or console interface.

我想您可以通过标准交互设置一个 Expect 脚本 运行 并在此过程中报告任何交互问题。

我怀疑任何程序都可以测试美学(即它看起来如何,等等...)但是您可以测试界面是否适合屏幕以及各种 windows 不适合t 重叠等。通过向 PyCurses 函数调用添加装饰器来跟踪各个部分的尺寸并报告任何重叠或问题。

有关 Python 装饰器的更多信息,请查看这篇文章:Understanding Python Decorators in 12 Easy Steps!