Merge pull request #2 from harlowja/start_on_enter

Have the start state 'on_exit' be called when exit occurs
This commit is contained in:
Joshua Harlow 2014-12-11 15:09:43 -08:00
commit a6fe13bc11
2 changed files with 8 additions and 2 deletions

View File

@ -239,7 +239,12 @@ class FiniteMachine(object):
if self._states[start_state]['terminal']:
raise excp.InvalidState("Can not start from a terminal"
" state '%s'" % (start_state))
self._current = _Jump(start_state, None, None)
# No on enter will be called, since we are priming the state machine
# and have not really transitioned from anything to get here, we will
# though allow on_exit to be called on the event that causes this
# to be moved from...
self._current = _Jump(start_state, None,
self._states[start_state]['on_exit'])
def copy(self, shallow=False, unfreeze=False):
"""Copies the current state machine.

View File

@ -123,7 +123,8 @@ class FSMTest(testcase.TestCase):
m.process_event('fall')
self.assertEqual([('down', 'beat'),
('up', 'jump'), ('down', 'fall')], enter_transitions)
self.assertEqual([('down', 'jump'), ('up', 'fall')], exit_transitions)
self.assertEqual([('start', 'beat'), ('down', 'jump'), ('up', 'fall')],
exit_transitions)
def test_run_iter(self):
up_downs = []