Ejemplo n.º 1
0
 def test_ignore_invalid_triggers(self):
     a_state = State('A')
     transitions = [['a_to_b', 'A', 'B']]
     # Exception is triggered by default
     b_state = State('B')
     m1 = Machine(None, states=[a_state, b_state], transitions=transitions,
                  initial='B')
     with self.assertRaises(MachineError):
         m1.a_to_b()
     # Exception is suppressed, so this passes
     b_state = State('B', ignore_invalid_triggers=True)
     m2 = Machine(None, states=[a_state, b_state], transitions=transitions,
                  initial='B')
     m2.a_to_b()
     # Set for some states but not others
     new_states = ['C', 'D']
     m1.add_states(new_states, ignore_invalid_triggers=True)
     m1.to_D()
     m1.a_to_b()  # passes because exception suppressed for D
     m1.to_B()
     with self.assertRaises(MachineError):
         m1.a_to_b()
     # Set at machine level
     m3 = Machine(None, states=[a_state, b_state], transitions=transitions,
                  initial='B', ignore_invalid_triggers=True)
     m3.a_to_b()