跳转到主要内容

针对Trio的Hypothesis插件

项目描述

https://github.com/python-trio/hypothesis-trio/actions/workflows/ci.yml/badge.svg?branch=master https://codecov.io/gh/python-trio/hypothesis-trio/branch/master/graph/badge.svg

欢迎使用 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 查看哈希值)

上传于 Python 3

支持者