假设扩展,允许生成与模式匹配的protobuf消息。
hypothesis-pb的Python项目详细描述
#假设原型[构建状态](https://travis-ci.org/hchastevens/hypothesis-protobuf.svg?(https://travis ci.org/hchasestevens/hypothesis protobuf)
[![PYPI版本](https://badge.fury.io/py/hypothesis pb.svg)(https://pypi.org/project/hypothesis pb)
![pypi-python版本](https://img.shields.io/pypi/pyversions/hypothesis-pb.svg)
[假设](http://hypothesis.works/)扩展,允许生成与架构匹配的[protobuf](https://developers.google.com/protocol-buffers/)消息。
编译后的protobuf模式模块“hypothesis protobuf”允许生成与protobuf消息类型匹配的假设策略。
>枚举客户端{
>客户端未知=0;
>客户端本地应用程序=1;
>客户端Web应用程序=2;
>客户端Web应用程序=3;
<
>消息用户{
>uint64 id=1;
>字符串屏幕名称=2;
>消息实例消息{
>uint64 time戳=1;
>客户端客户端=2;
>fixeedededed2;
32发送方IP=3;
用户发送方=4;
用户收件人=5;
字符串消息=6;
重复字节图像附件=7;
}
````
通过执行以下操作,可以从已编译的架构(`im-pb2.py`)生成“InstantMessage”的策略:
``python
从假设原型导入模块到策略
导入im-pb2
protobuf策略=模块到策略(im-pb2)
即时消息策略=protobuf_strategies[im_pb2.instantMessage]
````
,进而可用于生成“instantMessage”示例:
``python
>;即时消息的即时消息策略。例如:
timestamp:14420265020120117158477352
client:client:client:client:natitu-app
发件人IP:14651099037
发件人{
id:950948488734701077048
screen'u-name:“\364\210\210\240\2233\007\352\212\222I\354\217\251“
>
收件人{
id:14863005054719025962687
client:client:client:client:natitu-app
发件人IP:14655109037
发件人{351\274\240“
}
消息:“M\361\265\247\224\310\224\362\202\r\347\227\245\n\352\202m]\361\253\237\2700”
图像附件:“\236RN\267\252\363-S\235”
图像附件:“\256\376ZP-”
图像附件:“\340”
````
或用作测试策略(参见[假设快速启动指南](https://hypothesis.readthedocs.io/en/latest/quickstart.html)):
``python
来自给定的假设导入
@given(即时消息=protobuf_strategies[im pb2.instantMessage])
def test_instant_message处理器(即时消息):
assert process_message(即时消息)将使用多个即时消息运行示例在为给定protobuf模块生成策略时,可以提供字段特定的覆盖。这些重写必须是从全域名称到策略的映射,例如:
``python
从hypothesis\u protobuf import modules到hypothesis
从hypothesis import strategies as st
import im-pb2
strategy\u overrides={
'im.instantMessage.timestamp':st.floats(
min-value=0,
最大值=2E9
)
允许将上述重写指定为:
``python
from hypothesis_protobuf import full_field_name
from hypothesis import strategies as st
import im_pb2
strategy_overrides={
full_field_name(im pb2.instantMessage,“timestamp”):st.floats(
min_value=0,
最大值=2E9
)
}
````
在消息策略应该从上面选择的情况下提供ride或从默认字段值中,可以使用“optional”函数:
``python
from hypothesis\u protobuf import optional
from hypothesis import strategies as st
strategy\u overrides={
'im.instantMessage.timestamp':可选(
st.floats(min\u value=0,max_value=2e9)
)
}
```
最后,重写也可以作为函数提供,采用字段的默认策略并返回新策略。使用此方法,可以将上述内容重写为:
``python
strategy\u overrides={
'im.instantMessage.timestamp':(
lambda strategy:strategy.filter(lambda value:value<;=2e9)
)
}
```
[![PYPI版本](https://badge.fury.io/py/hypothesis pb.svg)(https://pypi.org/project/hypothesis pb)
![pypi-python版本](https://img.shields.io/pypi/pyversions/hypothesis-pb.svg)
[假设](http://hypothesis.works/)扩展,允许生成与架构匹配的[protobuf](https://developers.google.com/protocol-buffers/)消息。
编译后的protobuf模式模块“hypothesis protobuf”允许生成与protobuf消息类型匹配的假设策略。
>枚举客户端{
>客户端未知=0;
>客户端本地应用程序=1;
>客户端Web应用程序=2;
>客户端Web应用程序=3;
<
>消息用户{
>uint64 id=1;
>字符串屏幕名称=2;
>消息实例消息{
>uint64 time戳=1;
>客户端客户端=2;
>fixeedededed2;
32发送方IP=3;
用户发送方=4;
用户收件人=5;
字符串消息=6;
重复字节图像附件=7;
}
````
通过执行以下操作,可以从已编译的架构(`im-pb2.py`)生成“InstantMessage”的策略:
``python
从假设原型导入模块到策略
导入im-pb2
protobuf策略=模块到策略(im-pb2)
即时消息策略=protobuf_strategies[im_pb2.instantMessage]
````
,进而可用于生成“instantMessage”示例:
``python
>;即时消息的即时消息策略。例如:
timestamp:14420265020120117158477352
client:client:client:client:natitu-app
发件人IP:14651099037
发件人{
id:950948488734701077048
screen'u-name:“\364\210\210\240\2233\007\352\212\222I\354\217\251“
>
收件人{
id:14863005054719025962687
client:client:client:client:natitu-app
发件人IP:14655109037
发件人{351\274\240“
}
消息:“M\361\265\247\224\310\224\362\202\r\347\227\245\n\352\202m]\361\253\237\2700”
图像附件:“\236RN\267\252\363-S\235”
图像附件:“\256\376ZP-”
图像附件:“\340”
````
或用作测试策略(参见[假设快速启动指南](https://hypothesis.readthedocs.io/en/latest/quickstart.html)):
``python
来自给定的假设导入
@given(即时消息=protobuf_strategies[im pb2.instantMessage])
def test_instant_message处理器(即时消息):
assert process_message(即时消息)将使用多个即时消息运行示例在为给定protobuf模块生成策略时,可以提供字段特定的覆盖。这些重写必须是从全域名称到策略的映射,例如:
``python
从hypothesis\u protobuf import modules到hypothesis
从hypothesis import strategies as st
import im-pb2
strategy\u overrides={
'im.instantMessage.timestamp':st.floats(
min-value=0,
最大值=2E9
)
允许将上述重写指定为:
``python
from hypothesis_protobuf import full_field_name
from hypothesis import strategies as st
import im_pb2
strategy_overrides={
full_field_name(im pb2.instantMessage,“timestamp”):st.floats(
min_value=0,
最大值=2E9
)
}
````
在消息策略应该从上面选择的情况下提供ride或从默认字段值中,可以使用“optional”函数:
``python
from hypothesis\u protobuf import optional
from hypothesis import strategies as st
strategy\u overrides={
'im.instantMessage.timestamp':可选(
st.floats(min\u value=0,max_value=2e9)
)
}
```
最后,重写也可以作为函数提供,采用字段的默认策略并返回新策略。使用此方法,可以将上述内容重写为:
``python
strategy\u overrides={
'im.instantMessage.timestamp':(
lambda strategy:strategy.filter(lambda value:value<;=2e9)
)
}
```