Skip to content

Commit

Permalink
MWE for #596: transition in a parent model doesn't change state in th…
Browse files Browse the repository at this point in the history
…e nested model
  • Loading branch information
Juno Woods committed Nov 28, 2022
1 parent d771d40 commit 5d9e3f9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,42 @@ def to(self):
self.assertTrue(mock.called)
self.assertTrue(model2.is_B())

def test_nested_model(self):
"""Transition into a nested state using a parent model also changes the state of the nested model"""
class NestedModel:
def __init__(self):
self.machine = HierarchicalMachine(
states=['a', 'b'],
transitions=[{'trigger': 'subgo', 'source': 'a', 'dest': 'b'}],
model=self
)

class Model:
def __init__(self, child):
self.machine = HierarchicalMachine0(
states=[
{'name': 'A'},
{'name': 'B', 'children': child.machine}
],
transitions=[
{'trigger': 'go', 'source': 'A', 'dest': 'B_a'},
{'trigger': 'go', 'source': 'B_b', 'dest': 'A'},
],
model=self,
initial='A')

child = NestedModel()
model = Model(child)
assert model.is_A()
model.go()
assert model.is_B_a()
assert child.is_a()
model.subgo()
assert model.is_B_b()
assert child.is_b()
model.go()
assert model.is_A()

def test_trigger_parent(self):
parent_mock = MagicMock()
exit_mock = MagicMock()
Expand Down

0 comments on commit 5d9e3f9

Please sign in to comment.