Commits

Ian George committed d9a09de

Removed prints from history test and added count assertion

  • Participants
  • Parent commits 580afbd

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):
         bad_states = []
         state_names = set(self.states.keys())
         self.states[fsm_state.name] = fsm_state
 
     def execute(self, new_state, model):
+        if self.verify_on_execute:
+            self.verify()
+
         if not new_state in self.states:
             raise FSM_StateDoesNotExist(new_state)
 

statemachine/tests.py

     if state_to == "end" and state_from == "step3":
         return True
 
-testfsm = FSM(FSM_State("start" ,["step1", "step1a", "step1b", "step1c"]))
+testfsm = FSM(FSM_State("start" ,["step1a", "step1b", "step1c"]))
 testfsm.add(FSM_State("step1a", ["step2",]))
 testfsm.add(FSM_State("step1b", ["step2",]))
 testfsm.add(FSM_State("step1c", ["step2",]))
         """ End to end smoke test of the transitions """
         self.fsm.transition("step1a", None)
         self.fsm.transition("step2", None)
+
         #reload to check state is saved and reinstated
         self.assertEqual(self.fsm.state, "step2")
         fsm_id = self.fsm.id
 
     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):
         self.fsm.transition("step2", None)
         self.fsm.transition("end", None)
 
-        for item in self.fsm.state_history.all():
-            print "%s: %s - %s" % (item.change_date, item.from_state, item.to_state)
+        self.assertEqual(self.fsm.state_history.count(), 3)