Coeus C远程集成测试客户端协议的Python实现。
coeus-test的Python项目详细描述
腔
coeus是用于远程(tcp)集成测试的json消息协议的python客户端实现。
安装
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",...)