Commits

dr0id committed 1ee0a37

fixe bug calling init after calling exit again always raised InitAlreadyCalledError

Comments (0)

Files changed (4)

trunk/symplehfsm/changes.txt

 
 2.0.2.0 (date 01.05.2012)
+	- fixe bug calling init after calling exit again always raised InitAlreadyCalledError
 	- added extensive documentation/tutorial to mousefollower examle
 	- added state machine graph to the testablestatemachine example, cleaned up code
 	- renamed SympleDictHFSM class to SympleHFSM

trunk/symplehfsm/examples/TestHFSM/symplehfsm_demo.py

         
     def test_initial_transition_state(self):
 #    init:  s0 ->  s11:   s0.entry, s1.entry, s11.entry
+        self.state_machine.exit() # make sure the state machine is uninitialized
         v = self.TestVector("init", self.states["s0"], self.state_machine.init, self.states["s11"], [self.TActions.AEnum.ENTERS0, self.TActions.AEnum.ENTERS1, self.TActions.AEnum.ENTERS11])
         self.prove_one_transition(self.state_machine, self.actions, v)
 

trunk/symplehfsm/symplehfsm.py

             InitAlreadyCalledError if calle more than once.
 
         """
-        if self.current_state is not None:
+        if self.handle_event != self._handle_event_not_inititalized:
             raise self.InitAlreadyCalledError(str(self))
 
         node = self._structure.states[self._structure.root]
                 node.exit(self.actions)
             node = node.parent
         self._current_state = None
+        self.handle_event = self._handle_event_not_inititalized
 
     def _handle_event_not_inititalized(self, *args):
         """

trunk/symplehfsm/test/test_symplehfsm.py

         self.machine.init()
         self.machine.exit()
         self.machine.exit()
+        
+    def test_calling_init_after_exit_should_initialize_normally(self):
+        self.machine.init()
+        self.machine.exit()
+        self.machine.init()
 
 
 # -----------------------------------------------------------------------------