diff --git a/tests/test_nesting.py b/tests/test_nesting.py index f7afd094..a066c29b 100644 --- a/tests/test_nesting.py +++ b/tests/test_nesting.py @@ -425,6 +425,29 @@ def test_get_triggers(self): self.assertEqual(len(trans), 3) self.assertTrue('relax' in trans) + def test_get_nested_transitions(self): + seperator = self.state_cls.separator + states = ['A', {'name': 'B', 'children': ['1', '2', {'name': '3', 'children': ['a', 'b'], + 'transitions': [['inner', 'a', 'b'], + ['inner', 'b', 'a']]}], + 'transitions': [['mid', '1', '1'], + ['mid', '2', '3'], + ['mid', '3', '1'], + ['mid2', '2', '3'], + ['mid_loop', '1', '1']]}] + transitions = [['outer', 'A', 'B'], + ['outer', ['A', 'B'], 'C']] + machine = self.stuff.machine_cls(states=states, transitions=transitions, initial='A', auto_transitions=False) + self.assertEqual(10, len(machine.get_transitions())) + self.assertEqual(2, len(machine.get_transitions(source='A'))) + self.assertEqual(2, len(machine.get_transitions('inner'))) + self.assertEqual(3, len(machine.get_transitions('mid'))) + self.assertEqual(3, len(machine.get_transitions(dest='B{0}1'.format(seperator)))) + self.assertEqual(2, len(machine.get_transitions(source='B{0}2'.format(seperator), + dest='B{0}3'.format(seperator)))) + self.assertEqual(1, len(machine.get_transitions(source='B{0}3{0}a'.format(seperator), + dest='B{0}3{0}b'.format(seperator)))) + def test_internal_transitions(self): s = self.stuff s.machine.add_transition('internal', 'A', None, prepare='increase_level') diff --git a/tests/test_nesting_legacy.py b/tests/test_nesting_legacy.py index 97155748..79c19b82 100644 --- a/tests/test_nesting_legacy.py +++ b/tests/test_nesting_legacy.py @@ -94,6 +94,9 @@ def test_add_nested_state(self): def test_child_condition_persistence(self): pass # not supported by legacy machine + def test_get_nested_transitions(self): + pass # not supported by legacy machine + class TestReuseLegacySeparatorDefault(TestReuseSeparatorBase): diff --git a/transitions/extensions/nesting.py b/transitions/extensions/nesting.py index 9e1b3ac6..566e29c3 100644 --- a/transitions/extensions/nesting.py +++ b/transitions/extensions/nesting.py @@ -659,14 +659,7 @@ def get_transitions(self, trigger="", source="*", dest="*"): with self(): source_path = [] if source == "*" else source.split(self.state_cls.separator) dest_path = [] if dest == "*" else dest.split(self.state_cls.separator) - if source_path: - transitions = [] - while source_path: - transitions.extend(self.get_nested_transitions(trigger, source_path, dest_path)) - source_path.pop() - return transitions - else: - return self.get_nested_transitions(trigger, None, dest_path) + return self.get_nested_transitions(trigger, source_path, dest_path) def get_triggers(self, *args): """ Extends transitions.core.Machine.get_triggers to also include parent state triggers. """