diff --git a/tests/test_parallel.py b/tests/test_parallel.py index e972ae6a..9db7df5a 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -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): diff --git a/transitions/extensions/nesting.py b/transitions/extensions/nesting.py index 0be74922..81abd7ce 100644 --- a/transitions/extensions/nesting.py +++ b/transitions/extensions/nesting.py @@ -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', []))