针对Trio的Hypothesis插件
项目描述
欢迎使用 hypothesis-trio!
Hypothesis为非状态测试直接支持Trio。该项目旨在支持状态模式 ;-)
许可证:您可以选择MIT或Apache许可证2.0
用法
将 hypothesis.stateful.RuleBasedStateMachine 替换为 hypothesis_trio.stateful.TrioRuleBasedStateMachine
from hypothesis_trio.stateful import TrioRuleBasedStateMachine, run_state_machine_as_test
def test_trio_number_modifier(hypothesis_settings):
class NumberModifier(TrioRuleBasedStateMachine):
folders = Bundle('folders')
files = Bundle('files')
@initialize(target=folders)
async def init_folders(self):
await trio.sleep(0)
return '/'
@rule(target=folders, name=name_strategy)
async def create_folder(self, parent, name):
await trio.sleep(0)
return '%s/%s' % (parent, name)
@rule(target=files, name=name_strategy)
async def create_file(self, parent, name):
await trio.sleep(0)
return '%s/%s' % (parent, name)
async def teardown(self):
await trio.sleep(0)
run_state_machine_as_test(NumberModifier, settings=hypothesis_settings)
Trio-Asyncio支持
trio-asyncio 允许混合使用asyncio和trio代码。为了在测试中支持它,您应使用 hypothesis_trio.stateful.TrioAsyncioRuleBasedStateMachine
class CheckAsyncioLoop(TrioAsyncioRuleBasedStateMachine):
@initialize()
async def initialize(self):
assert self.get_asyncio_loop() == asyncio.get_event_loop()
await trio_asyncio.aio_as_trio(lambda: asyncio.sleep(0))
项目详情
下载文件
下载适合您平台的项目文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
hypothesis-trio-0.6.0.tar.gz (19.6 kB 查看哈希)
构建版本
hypothesis_trio-0.6.0-py3-none-any.whl (15.7 kB 查看哈希值)
关闭
hypothesis-trio-0.6.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d7ab108ac99758011b20f2448f1b1269375c68c1ffda9e4468600a4975ff955c |
|
MD5 | f0cf91ba083b6ee91f3fe0460f8d4036 |
|
BLAKE2b-256 | 2578007b68f95bba5854a99a106a2e2197478320a80c0abfa4c17d40d46c4b66 |
关闭
hypothesis_trio-0.6.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3ac261dc6fcf3862d7d57ffa52d294539f8d807ac9483d58a8060df3c9e856fc |
|
MD5 | 26e73e711c8803abf5b2dce220f15673 |
|
BLAKE2b-256 | cf2bb22113f2076b5e733a2d69ba3e28397f42e09b884df69ecac1cfaa33e221 |