def test_with_HSM_instance(self): states = { 'root': State({ 'left': State({ 'left_A': State(), 'left_B': State(), }), 'middle': State({ 'middle_A': State(), 'middle_B': State(), 'middle_C': State(), }), 'right': State({ 'right_A': State({ 'right_A_1': State(), 'deep': State(), 'right_A_2': State(), }), 'right_B': State(), }) }) } flattened = HSM(states, {}, skip_validation=True).flattened left_B = get_state_by_sig(('left_B',), flattened) deep = get_state_by_sig(('deep',), flattened) exits, parent, entries = get_path(deep, left_B) exits = [st.name for st in exits] entries = [st.name for st in entries] assert exits == ['deep', 'right_A', 'right'] assert parent.name == 'root' assert entries == ['left', 'left_B']
def test_branching(self): root = MockState(parent=None) left = MockState(parent=root) left_A = MockState(parent=left) left_B = MockState(parent=left) middle = MockState(parent=root) middle_A = MockState(parent=middle) right = MockState(parent=root) right_A = MockState(parent=right) right_A_1 = MockState(parent=right_A) right_A_2 = MockState(parent=right_A) assert get_path(root, root) == ([], root, []) assert get_path(left, left) == ([], left, []) assert get_path(left_A, left_B) == ([left_A], left, [left_B]) assert get_path(left_B, left_A) == ([left_B], left, [left_A]) assert get_path(middle, root) == ([middle], root, []) assert get_path(root, middle) == ([], root, [middle]) assert get_path(middle_A, left_A) == ([middle_A, middle], root, [left, left_A]) assert get_path(right_A_1, left) == ([right_A_1, right_A, right], root, [left]) assert get_path(right_A_2, left_B) == ([right_A_2, right_A, right], root, [left, left_B]) assert get_path(left_B, right_A_2) == ([left_B, left], root, [right, right_A, right_A_2]) assert get_path(right_A, root) == ([right_A, right], root, []) assert get_path(root, right_A) == ([], root, [right, right_A])