Trio的假设插件
hypothesis-trio的Python项目详细描述
欢迎来到hypothesis-trio!
假设支持非状态测试的开箱即用trio。 此项目旨在支持状态模式;-)
许可证:您可以选择MIT或Apache许可证2.0
用法
将hypothesis.stateful.RuleBasedStateMachine替换为hypothesis_trio.stateful.TrioRuleBasedStateMachine:
fromhypothesis_trio.statefulimportTrioRuleBasedStateMachine,run_state_machine_as_testdeftest_trio_number_modifier(hypothesis_settings):classNumberModifier(TrioRuleBasedStateMachine):folders=Bundle('folders')files=Bundle('files')@initialize(target=folders)asyncdefinit_folders(self):awaittrio.sleep(0)return'/'@rule(target=folders,name=name_strategy)asyncdefcreate_folder(self,parent,name):awaittrio.sleep(0)return'%s/%s'%(parent,name)@rule(target=files,name=name_strategy)asyncdefcreate_file(self,parent,name):awaittrio.sleep(0)return'%s/%s'%(parent,name)asyncdefteardown(self):awaittrio.sleep(0)run_state_machine_as_test(NumberModifier,settings=hypothesis_settings)
支持Trio Asyncio
trio-asyncio允许将异步代码和三元代码混合在一起。 要在测试中支持它,您应该使用hypothesis_trio.stateful.TrioAsyncioRuleBasedStateMachine:
classCheckAsyncioLoop(TrioAsyncioRuleBasedStateMachine):@initialize()asyncdefinitialize(self):assertself.get_asyncio_loop()==asyncio.get_event_loop()awaittrio_asyncio.aio_as_trio(lambda:asyncio.sleep(0))