测试repls的对话类

dialogue-tester的Python项目详细描述


对话类

Dialogue类帮助测试repls(带有read eval print循环的交互式解释器)。

给定一个多行交互式会话脚本,一个Dialogue实例通过提供一个fake_input方法来模拟用户交互,该方法可以替换python 3中的input内置函数。

如何使用

您可以编写repl函数以接受输入函数作为可选参数,也可以对python的内置input进行monkey补丁。无论哪种方式,您都可以用绑定到Dialogue实例的fake_input方法替换标准的input。每次调用该方法时,该方法都会从会话脚本中打印下一个提示和假用户输入,然后将相同的用户输入字符串返回给repl进行处理。

Dialogue.sessioninstance属性保存一个多行字符串,其中包含所有提示、用户输入和测试中repl的预期输出。这用于assert测试用例。

请参阅dialogue_test.py模块,以获取两个简单的repl,它们运行Dialogue类。

Note: the .session attribute is normalized with the dialogue.normalize() function. Use that function to normalize the output captured by your testing framework as well. This normalization removes trailing whitespace from each line, preserving only the newlines separating them, and also removes leading and trailing whitespace from the session as a whole. This avoids many issues with linters and IDEs complaining about trailing whitespace, and also makes it easier to edit the session examples in tests. See the tests in this package for use of normalize in test assertions.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将特定于语言环境的字符串转换为BigDecimal的最佳方法   java生成的数字在下降的水平上增加   java如何验证列表中的元素是否按字母顺序排序   java无法使用Jintellitype包com。梅洛器皿   java Hibernate显示来自JComboBox的记录   java更改模拟器屏幕分辨率?   java如何从可移动/辅助SD卡中删除文件   java检查在MySQL中插入时数据库中是否存在给定的用户名   java如何替换线程。无限循环中的sleep()?   java如何从数据库中获取一列的字符串数据作为数组数据   将内容存储在缓冲区中的java   java ControllerAdvice不处理引发的异常   Java Maven问题   java NullPointerException试图从方法返回2D对象数组时   这个简单的Java代码有什么问题?   java如何删除或访问pom文件中插件的构建时间戳   java销售收据,多选(if/else),while循环,客户更改选择的能力   Java:基于字符串的加载类方法   java OrientDB服务器部分忽略OrientDB_HOME