def test_ordered_transition_error(self): m = Machine(states=['A'], initial='A') with self.assertRaises(ValueError): m.add_ordered_transitions() m.add_state('B') m.add_ordered_transitions() m.add_state('C') with self.assertRaises(ValueError): m.add_ordered_transitions(['C'])
def build_statemachine(model): sm = Machine( model=model, initial='init', ignore_invalid_triggers=True, ) for symbol in dir(model): match = re.match(r'(\w+)__(\w+)', symbol, flags=re.ASCII) if not match: continue # state names in HSMs MUST NOT contain underscores. (TODO) state, event = match.groups() sm.add_state(state) sm.add_transition(trigger=event, source=state, dest=None, after=symbol) return sm