Disallow adding transitions from terminal states
Terminal states are by there very nature terminal and can not have transitions to other states on any kind of event so on add make sure we disallow those types of transitions to even be created in the first place. Change-Id: I70321e9482a0d053a8cb0bc89a766b5fbc82f69e
This commit is contained in:
parent
59d34fa3ed
commit
89656ae907
|
@ -190,6 +190,10 @@ class FiniteMachine(object):
|
|||
raise excp.NotFound("Can not add a transition on event '%s' that"
|
||||
" ends in a undefined state '%s'"
|
||||
% (event, end))
|
||||
if self._states[start]['terminal']:
|
||||
raise excp.InvalidState("Can not add a transition on event '%s'"
|
||||
" that starts in the terminal state '%s'"
|
||||
% (event, start))
|
||||
self._transitions[start][event] = _Jump(end,
|
||||
self._states[end]['on_enter'],
|
||||
self._states[start]['on_exit'])
|
||||
|
|
|
@ -60,6 +60,12 @@ class FSMTest(testcase.TestCase):
|
|||
m.add_state('unknown')
|
||||
self.assertIn('unknown', m)
|
||||
|
||||
def test_no_add_transition_terminal(self):
|
||||
m = self._create_fsm('up')
|
||||
m.add_state('down', terminal=True)
|
||||
self.assertRaises(excp.InvalidState,
|
||||
m.add_transition, 'down', 'up', 'jump')
|
||||
|
||||
def test_duplicate_state(self):
|
||||
m = self._create_fsm('unknown')
|
||||
self.assertRaises(excp.Duplicate, m.add_state, 'unknown')
|
||||
|
|
Loading…
Reference in New Issue