cmd2的外部测试插件。允许外部调用命令,就像从cmd2 pyscript调用命令一样
cmd2-ext-test的Python项目详细描述
cmd2外部测试插件
目录
概述
此插件通过公开具有相同上下文的access cmd2命令来支持对cmd2应用程序的测试 在cmd2 pyscript中。这允许验证应用程序对pyscripts的支持。在
cmd2应用程序示例
下面的简短示例演示如何混合使用外部测试插件来创建一个fixture进行测试 您的cmd2应用程序。在
定义cmd2应用程序
importcmd2classExampleApp(cmd2.Cmd):"""An class to show how to use a plugin"""def__init__(self,*args,**kwargs):# gotta have this or neither the plugin or cmd2 will initializesuper().__init__(*args,**kwargs)defdo_something(self,arg):self.last_result=5self.poutput('this is the something command')
定义测试夹具
在测试中,为cmd2应用程序定义一个fixture
^{pr2}$编写测试
现在编写测试,使用app_cmd
函数访问应用程序
cmd2应用程序的命令。这允许在中调用应用程序的命令
与用户键入的格式相同。调用命令的结果与返回的结果相匹配
使用cmd2的pyscript命令运行python脚本,该命令提供stdout、stderr和
命令的结果数据。在
fromcmd2importCommandResultdeftest_something(example_app):# execute a commandout=example_app.app_cmd("something")# validate the command output and result dataassertisinstance(out,CommandResult)assertstr(out.stdout).strip()=='this is the something command'assertout.data==5
许可证
cmd2uses the very liberal MIT license。 我们邀请插件作者考虑做同样的事情。在
- 项目
标签: