@@ -372,3 +372,43 @@ This is not recommended as it bypasses some important internal functions,
372
372
including reporting of statistics such as runtimes and :func: `~hypothesis.event `
373
373
calls. It was originally added to support custom ``__init__ `` methods, but
374
374
you can now use :func: `~hypothesis.stateful.initialize ` rules instead.
375
+
376
+ -------------------------
377
+ Adapting stateful testing
378
+ -------------------------
379
+
380
+ You can adapt stateful tests in a similar way to adapting regular strategies.
381
+ See (https://hypothesis.readthedocs.io/en/latest/data.html#adapting-strategies) for more details on how each of these strategies work.
382
+
383
+
384
+ .. This is not recommended as it bypasses some important internal functions,
385
+ .. including reporting of statistics such as runtimes and :func:`~hypothesis.event`
386
+ .. calls. It was originally added to support custom ``__init__`` methods, but
387
+ .. you can now use :func:`~hypothesis.stateful.initialize` rules instead.
388
+
389
+ .. code :: python
390
+
391
+ >> > class Machine (RuleBasedStateMachine ):
392
+ >> > bun = Bundle(" bun" )
393
+ >> >
394
+ >> > @ initialize(target = buns)
395
+ >> > def create_bun (self ):
396
+ >> > return multiple(1 , 2 )
397
+ >> >
398
+ >> > @ rule(bun = buns.map(lambda x : - x))
399
+ >> > def use_map (self , bun ):
400
+ >> > print (" Bun example is negative." )
401
+ >> >
402
+ >> > @ rule(bun = buns.filter(lambda x : x > 1 ))
403
+ >> > def use_filter (self , bun ):
404
+ >> > print (" Bun example is greater than 1." )
405
+ >> >
406
+ >> > @ rule(bun = buns.flatmap(lambda n : lists(lists(integers(), min_size = n, max_size = n))))
407
+ >> > def use_flatmap (self , bun ):
408
+ >> > print (" Bun example is a unique structure." )
409
+ >> >
410
+ >> > @ rule(bun = buns.map(lambda x : - x).filter(lambda x : x < - 1 ))
411
+ >> > def use_chain_strategies (self , bun ):
412
+ >> > print (" Bun example uses chained strategies!" )
413
+ >> >
414
+
0 commit comments