Hypothesis plugin for trio
Project description
Welcome to hypothesis-trio!
Hypothesis supports Trio out of the box for non-stateful tests. This project aims at supporting the stateful mode ;-)
License: Your choice of MIT or Apache License 2.0
Usage
Replace hypothesis.stateful.RuleBasedStateMachine by 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)
Support for Trio-Asyncio
trio-asyncio allows to mix asyncio and trio code altogether. To support it in your test, you should use 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))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hypothesis-trio-0.4.0.tar.gz
(18.0 kB
view details)
Built Distribution
File details
Details for the file hypothesis-trio-0.4.0.tar.gz
.
File metadata
- Download URL: hypothesis-trio-0.4.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603f39d8a20c0d303e2f5167b1686e8403684dab8cd2839f6bbe7926c97c4201 |
|
MD5 | 077b49dc49c5f9e0781abd6b8cabb1ed |
|
BLAKE2b-256 | 513674c82e4cfc755f822f5d37164787ee967df5162af30995c0cab660c9c720 |
File details
Details for the file hypothesis_trio-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: hypothesis_trio-0.4.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0b0f0f524cb43a45494e19df7f6db97c96e391e4376f68fe719c2b03c008a2 |
|
MD5 | 015588fa3fe5cc4e451a21fe9a54e440 |
|
BLAKE2b-256 | 79208c1e9e43d6ad402f723249d7eba5e9393ff16ff5f73ba4252b98c9bba1fc |