跳转到主要内容

Python交互式命令运行器。

项目描述

ICommandlib

Main branch status

Icommandlib是一个交互式命令行运行器,设计(与pexpect不同)以能够在虚拟终端窗口中运行命令行应用程序并截取屏幕截图。

它被设计用于构建自我重写的、生成文档的测试 例如这个,用于具有 hitchstory框架 的交互式命令行应用程序。

ICommandLib可以捕获终端文本屏幕截图和“stripshots”——带有屏幕右侧和底部所有空白被移除的终端屏幕截图。

示例

favoritecolor.py

answer = input("favorite color:")
print(f"Your favorite color is {answer}")
answer = input("favorite movie:")
print(f"Your favorite color is {answer}")

代码

from icommandlib import ICommand
from commandlib import python
from pathlib import Path

process = ICommand(python("favoritecolor.py")).run()
process.wait_until_output_contains("favorite color:")
process.send_keys("red\n")
process.wait_until_output_contains("favorite movie:")
process.send_keys("the usual suspects\n")
process.wait_until_on_screen("favorite color")
process.wait_for_successful_exit()

Path("stripshot.txt").write_text(process.stripshot())
  • 当代码运行完成时。

则stripshot.txt文件的文本内容将为

Your favorite color is red
favorite movie:the usual suspects
Your favorite color is the usual suspects```

With height 4 and width 41.







## Install

```bash
$ pip install icommandlib

使用ICommandLib

由以下支持