Coeus C远程集成测试客户端协议的Python实现。

coeus-test的Python项目详细描述


coeus是用于远程(tcp)集成测试的json消息协议的python客户端实现。

pypitravis

安装

coeus是作为需求添加到python单元测试项目中的。只需添加对coeus-test的引用。

pip install coeus-test

开始

词汇表

client:用于通过TCP连接到服务器应用程序的类。

message:定义通信的特定json格式(prototcol)。

^ {STR 1 } $TestOntase:在服务器应用程序中存在的^ {< CD3>}的抽象概念。通常通过其ID访问。

客户端设置

客户端必须通过IP和端口连接到服务器应用程序。您可以按如下方式调用连接:

importclientcli=client.Client(tcp_port=31203)cli.connect()

默认情况下,它将尝试连接到ip:127.0.0.1

命令

命令是发送到服务器,然后等待接收消息的特定阻塞调用。每个命令都有响应。

Commands do not handle any validation of message received from unity client.

importcommands

查询命令

查询实体已注册

此命令向unity应用程序询问实体的状态。

Usage

result=commands.query_entity_is_registered(cli,"myEntityId")

Response

{"type":"query.entity.isRegistered","payload":{"result":true|false}}

等待命令

等待注册的实体

此命令将阻塞,直到实体达到特定状态。默认情况下,它将一直阻止,直到实体注册为止。如果命令超过指定的超时,则继续失败。

Usage

//is_registered,timeout_secondsoptional...result=commands.await_entity_registered(cli,"myEntityId",is_registered=True,timeout_seconds=60)

Response

{"type":"await.continue","payload":{"success":true|false}}

获取命令

获取实体

此命令要求服务器序列化testentity并发送它。

Usage

result=commands.fetch_entity(cli,"myEntityId")

Success Response

{"type":"fetch.entity","payload":{"test_entity":{...}|null}}

调用命令

调用实体方法

此命令允许python单元测试调用服务器testentity上的方法并返回结果。

Usage

parameters={"statName":"score"}result=commands.invoke_entity_method(cli,"myEntityId","GetPlayerStat",parameters)

在C代码中,这将查找具有以下签名的方法:

publicintGetPlayerStat(IDynamicObjectparameters){varstatName=parameters.GetValue<string>("statName");...returnstat;}

Response

{"type":"invoke.entity.method","payload":{"is_error":false,"error_message":null,"result":32}}

如果存在c异常,则error_message将包含异常消息。

断言

这些命令不会验证服务器的响应。要轻松做到这一点,请使用断言。

importassertions...# Fails assert if False returned from response...assertions.assert_entity_is_registered(cli,"myEntityId")# Fails if timeout exceeded...assertions.assert_await_entity_registered(cli,"myEntityId")# Fails if the test_entity is None...result=assertions.assert_fetch_entity(cli,"myEntityId")# Fails if is_error == True, AssertException with message provided...result=assert_invoke_entity_method(cli,"myEntityId","GetPlayerStat",...)

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

推荐PyPI第三方库


热门话题
用户界面java,使用gui连接到另一台计算机/服务器的文件系统   运行sbt的ubuntu返回错误:“javahome需要<path>参数”   java如何在Android中处理许多ImageView而不出现内存问题?   查询中非法字符的java相同URL失败   安卓取消引用可能会产生“java”。lang.NullPointerException'   java中的indexoutofboundsexception“java.lang.ArrayIndexOutOfBoundsException”错误   xml Java将dom保存到文件>文件在程序结束后由另一个进程打开   Java的垃圾收集器是如何工作的?   Java如何筛选值(列表)   java处理字符串我怎样才能像在真实的书籍中一样在上面部分生成“小数字”呢?   java SonarQube是否有一个API来获取所有项目分析的一部分?   java startActivity(intent)什么都不做   JAVAutil。扫描器类Java   java如何从Firebase更新电子邮件?UpdateMail方法已被弃用   java Hibernate。如何正确组织带有注释的onetomany关系?   在java中获得卷标和驱动器号之间的映射(而不是FileSystemView)的解决方法是什么   java查找文件的路径