Skip to content

Commit dc0ba73

Browse files
committed
This fixes #211; also fixes issues with data_files
LICENSE has to be an array. This may prevented proper installation.
1 parent 2b79609 commit dc0ba73

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
package_data={'transitions': ['data/*'],
3030
'transitions.tests': ['data/*']
3131
},
32-
data_files=[('', 'LICENSE')],
32+
data_files=[('', ['LICENSE'])],
3333
install_requires=['six'],
3434
tests_require=tests_require,
3535
license='MIT',

tests/test_core.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,11 @@ def always_raises(event_data):
744744

745745
transitions = [
746746
{'trigger': 'go', 'source': 'A', 'dest': 'B'},
747-
{'trigger': 'planA', 'source': 'B', 'dest': 'C', 'conditions': always_fails},
748-
{'trigger': 'planB', 'source': 'B', 'dest': 'C', 'conditions': always_raises}
747+
{'trigger': 'planA', 'source': 'B', 'dest': 'A', 'conditions': always_fails},
748+
{'trigger': 'planB', 'source': 'B', 'dest': 'A', 'conditions': always_raises}
749749
]
750-
m = Machine(states=['A', 'B'], transitions=transitions,
751-
finalize_event=finalize_mock, initial='A', send_event=True)
750+
m = self.stuff.machine_cls(states=['A', 'B'], transitions=transitions,
751+
finalize_event=finalize_mock, initial='A', send_event=True)
752752

753753
m.go()
754754
self.assertEqual(finalize_mock.call_count, 1)
@@ -772,9 +772,9 @@ def always_raises(event):
772772
def finalize_callback(event):
773773
self.assertEqual(event.error, exception)
774774

775-
m = Machine(states=['A', 'B'], send_event=True, initial='A',
776-
before_state_change=always_raises,
777-
finalize_event=finalize_callback)
775+
m = self.stuff.machine_cls(states=['A', 'B'], send_event=True, initial='A',
776+
before_state_change=always_raises,
777+
finalize_event=finalize_callback)
778778

779779
with self.assertRaises(ZeroDivisionError):
780780
m.to_B()

transitions/extensions/nesting.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,37 @@ def _change_state(self, event_data):
124124
class NestedEvent(Event):
125125

126126
def _trigger(self, model, *args, **kwargs):
127-
tmp = self.machine.get_state(model.state)
128-
while tmp.parent and tmp.name not in self.transitions:
129-
tmp = tmp.parent
130-
if tmp.name not in self.transitions:
127+
state = self.machine.get_state(model.state)
128+
while state.parent and state.name not in self.transitions:
129+
state = state.parent
130+
if state.name not in self.transitions:
131131
msg = "%sCan't trigger event %s from state %s!" % (self.machine.id, self.name,
132132
model.state)
133133
if self.machine.get_state(model.state).ignore_invalid_triggers:
134134
logger.warning(msg)
135135
else:
136136
raise MachineError(msg)
137-
event = EventData(self.machine.get_state(model.state), self, self.machine,
138-
model, args=args, kwargs=kwargs)
139-
for t in self.transitions[tmp.name]:
140-
event.transition = t
141-
if t.execute(event):
142-
return True
143-
return False
137+
event_data = EventData(self.machine.get_state(model.state), self, self.machine,
138+
model, args=args, kwargs=kwargs)
139+
140+
for func in self.machine.prepare_event:
141+
self.machine._callback(func, event_data)
142+
logger.debug("Executed machine preparation callback '%s' before conditions." % func)
143+
144+
try:
145+
for t in self.transitions[state.name]:
146+
event_data.transition = t
147+
if t.execute(event_data):
148+
event_data.result = True
149+
break
150+
except Exception as e:
151+
event_data.error = e
152+
raise
153+
finally:
154+
for func in self.machine.finalize_event:
155+
self.machine._callback(func, event_data)
156+
logger.debug("Executed machine finalize callback '%s'." % func)
157+
return event_data.result
144158

145159

146160
class HierarchicalMachine(Machine):

0 commit comments

Comments
 (0)