1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 08:17:17 +00:00
test-tutorial-framework/solvable/src/test_fsm.py

38 lines
1.2 KiB
Python
Raw Normal View History

# This defines an FSM equvivalent to test_fsm.yml
from os.path import exists
2018-07-26 12:00:24 +00:00
from tfw.fsm import LinearFSM
2018-04-10 09:19:53 +00:00
from tfw.networking import MessageSender
class TestFSM(LinearFSM):
2018-04-19 09:22:43 +00:00
# pylint: disable=unused-argument
def __init__(self):
super().__init__(6)
2018-04-10 09:19:53 +00:00
self.message_sender = MessageSender()
self.subscribe_predicate('step_3', self.step_3_allowed)
@staticmethod
def step_3_allowed():
return exists('/home/user/workdir/allow_step_3')
2018-04-10 09:19:53 +00:00
def on_enter_1(self, event_data):
self.message_sender.send('FSM', 'Entered state 1!')
2018-04-10 09:19:53 +00:00
def on_enter_2(self, event_data):
filename = '/home/user/workdir/cat.txt'
with open(filename, 'w') as ofile:
ofile.write('As you can see it is possible to write arbitrary python code here.')
self.message_sender.send('FSM', f'Entered state 2! Written stuff to {filename}')
2018-04-10 09:19:53 +00:00
def on_enter_3(self, event_data):
self.message_sender.send('FSM', 'Entered state 3!')
2018-04-10 09:19:53 +00:00
def on_enter_4(self, event_data):
self.message_sender.send('FSM', 'Entered state 4!')
2018-04-10 09:19:53 +00:00
def on_enter_5(self, event_data):
self.message_sender.send('FSM', 'Entered state 5!')