Commits

Ian George committed e2410b8 Merge

whoo, branch merge

Comments (0)

Files changed (2)

statemachine/fsm.py

     """
     Simple FSM implementation.
     """
-    def __init__(self, initial_state):
+    def __init__(self, initial_state, verify_on_execute=True):
         self.states = {}
         self.add(initial_state)
         self.state = initial_state.name
         self.dbg = None
-
+        self.verify_on_execute = verify_on_execute
+        
     def verify(self):
         """
         Best only called on fully formed machines, checks for unreachable states
         """
         Transitions the machine to its new state.
         """
-        if not new_state in self.states:
+         if self.verify_on_execute:
+            self.verify()
+
+       if not new_state in self.states:
             raise FSM_StateDoesNotExist(new_state)
 
         exiting_state = self.states[self.state]

statemachine/tests.py

 
     def test_invalid_transition(self):
         """ Testing invalid transitions """
+
+        #check we are starting at "start"
         self.assertEqual(self.fsm.state, "start")
         
         with self.assertRaises(FSM_TransitionNotAllowed):
             self.fsm.transition("step3", None)
 
+        #check we are still at "start" after a failed transition
         self.assertEqual(self.fsm.state, "start")
 
     def test_transition_history(self):