Skip to content

Commit

Permalink
fix: allow a list of machines in "parallel" and thus initial to be a …
Browse files Browse the repository at this point in the history
…(list of) machines

- part of #507
- note that machine states must be unique!
  • Loading branch information
aleneum committed Aug 23, 2024
1 parent 4d8d103 commit 71ad1f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ def test_is_state_parallel(self):
assert m.is_P_2(allow_substates=True)
assert not m.is_A(allow_substates=True)

def test_reuse(self):
a = self.machine_cls(states=["A", "B"], initial="A")
b = self.machine_cls(states=["C", "D"], initial="D")
c = self.machine_cls(states=["A", {"name": "X", "parallel": [a, b]}], initial="A")
assert c.to_X()
assert c.state == ["X{}A".format(self.state_cls.separator),
"X{}D".format(self.state_cls.separator)]


@skipIf(pgv is None, "pygraphviz is not available")
class TestParallelWithPyGraphviz(TestParallel):
Expand Down
1 change: 1 addition & 0 deletions transitions/extensions/nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ def _add_dict_state(self, state, ignore_invalid_triggers, remap, **kwargs):
if state_parallel:
state_children = state_parallel
state['initial'] = [s['name'] if isinstance(s, dict)
else s.initial if isinstance(s, HierarchicalMachine)
else s for s in state_children]
else:
state_children = state.pop('children', state.pop('states', []))
Expand Down

0 comments on commit 71ad1f4

Please sign in to comment.