From aefa4024904ec92034d108d94768a388e8f1a9f6 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 26 Mar 2009 20:39:40 +0000 Subject: TutoriusV2 : Added test for set_state with same name twice - corrected core behavior in this case --- (limited to 'src/sugar/tutorius/core.py') diff --git a/src/sugar/tutorius/core.py b/src/sugar/tutorius/core.py index 901820f..4d53684 100644 --- a/src/sugar/tutorius/core.py +++ b/src/sugar/tutorius/core.py @@ -277,11 +277,8 @@ class FiniteStateMachine(State): self._states = state_dict or {} self.start_state_name = start_state_name - # If we have a filled input dictionary - if len(self._states) > 0: - self.current_state = self._states[self.start_state_name] - else: - self.current_state = None + # Set the current state to None - we are not executing anything yet + self.current_state = None # Register the actions for the FSM - They will be processed at the # FSM level, meaning that when the FSM will start, it will first @@ -357,6 +354,13 @@ class FiniteStateMachine(State): # state by that name - we must ignore this state change request as # it will be done elsewhere in the hierarchy (or it's just bogus). return + + if self.current_state != None: + if new_state_name == self.current_state.name: + # If we already are in this state, we do not need to change + # anything in the current state - By design, a state may not point + # to itself + return new_state = self._states[new_state_name] -- cgit v0.9.1