def test_chained_syntax(self): "States can be defined using chainable calls." sm = StateMachine("ABCD") action = Mock() state_action = Mock() sm.A.when(self.truecond).do(action).goto(sm.B) sm.A.when(self.falsecond).goto(sm.D) sm.B.set_action(state_action).when(self.truecond).goto(sm.C) sm.proceed() self.assertEquals(sm.state, "C") action.assert_called_with() state_action.assert_called_with()
def test_proceed_while_allowed(self): "Proceed returns False reaching a state with no allowed exits." sm = StateMachine("ABCGH") sm["A"].add_exit("C") sm["C"].add_exit("G", self.truecond) sm["G"].add_exit("B", self.falsecond) sm["B"].add_exit("H") self.assertFalse(sm.proceed()) self.assertEquals(sm.history.keys(), list("ACG"))
def test_proceed(self): "Proceed steps through all states and then returns True" sm = StateMachine("ABCGH") sm.A.add_exit(sm.C) sm.C.add_exit(sm.G) sm.G.add_exit(sm.B) sm.B.add_exit(sm.H) self.assertTrue(sm.proceed()) self.assertEquals(sm.history.keys(), list("ACGBH"))