Skip to content

Commit

Permalink
Merge 2998a61 into 9dedc70
Browse files Browse the repository at this point in the history
  • Loading branch information
potens1 committed Oct 24, 2018
2 parents 9dedc70 + 2998a61 commit d37962e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ class CustomMachine(Machine):
with self.assertRaises(MachineError):
m.fail()

def test_error_callback(self):
@add_state_features(Error)
class CustomMachine(Machine):
pass

mock_callback = MagicMock()

states = ['A', {"name": "B", "on_enter": mock_callback}, 'C']
transitions = [
["to_B", "A", "B"],
["to_C", "B", "C"],
]
m = CustomMachine(states=states, transitions=transitions, auto_transitions=False, initial='A')
m.to_B()
self.assertEqual(m.state, "B")
self.assertTrue(mock_callback.called)


def test_timeout(self):
mock = MagicMock()

Expand Down
1 change: 1 addition & 0 deletions transitions/extensions/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def enter(self, event_data):
"""
if not event_data.machine.get_triggers(self.name) and not self.is_accepted:
raise MachineError("Error state '{0}' reached!".format(self.name))
super(Error, self).enter(event_data)


class Timeout(State):
Expand Down

0 comments on commit d37962e

Please sign in to comment.