Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow a list of machines in "parallel" #687

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Made `transitions.core.(Async)TransitionConfigDict` a `TypedDict` which can be used to spot parameter errors during static analysis
- `Machine.add_transitions` and `Machine.__init__` expect a `Sequence` of configurations for transitions now
- Added 'async' callbacks to types in `asyncio` extension
- Bug #687: Instances of `HierarchicalMachine` can now directly be passed to "parallel" keyword in constructor; Machine states will be processed as a list and thus must be unique (thanks @translunar)

## 0.9.2 (August 2024)

Expand Down
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