Skip to content

Commit d573ed8

Browse files
committed
Fix flatmap on consuming bundles
1 parent fcc26c4 commit d573ed8

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

hypothesis/src/hypothesis/stateful.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def is_currently_empty(self, data):
638638

639639
def flatmap(self, expand):
640640
if self.draw_references:
641-
return type(self)(
641+
return Bundle(
642642
self.name,
643643
consume=self.__reference_strategy.consume,
644644
draw_references=False,

hypothesis/tests/cover/test_stateful.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,27 @@ def use_directly(self, bun):
14721472
run_state_machine_as_test(Machine)
14731473

14741474

1475+
def test_flatmap_can_consume_bundle():
1476+
class Machine(RuleBasedStateMachine):
1477+
strings = Bundle("strings")
1478+
1479+
@initialize(target=strings)
1480+
def set_initial(self):
1481+
return "sample text"
1482+
1483+
@rule(
1484+
target=strings,
1485+
character=consumes(strings).flatmap(lambda text: st.sampled_from(text)),
1486+
)
1487+
def consume_flatmapped(self, character):
1488+
assert isinstance(character, str)
1489+
assert len(character) == 1
1490+
return character
1491+
1492+
Machine.TestCase.settings = Settings(stateful_step_count=5, max_examples=10)
1493+
run_state_machine_as_test(Machine)
1494+
1495+
14751496
def test_use_bundle_within_other_strategies():
14761497
class Class:
14771498
def __init__(self, value):

0 commit comments

Comments
 (0)