1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 06:37:18 +00:00
test-tutorial-framework/solvable/src/test_fsm.py
2018-07-26 14:00:24 +02:00

38 lines
1.2 KiB
Python

# This defines an FSM equvivalent to test_fsm.yml
from os.path import exists
from tfw.fsm import LinearFSM
from tfw.networking import MessageSender
class TestFSM(LinearFSM):
# pylint: disable=unused-argument
def __init__(self):
super().__init__(6)
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')
def on_enter_1(self, event_data):
self.message_sender.send('FSM', 'Entered state 1!')
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}')
def on_enter_3(self, event_data):
self.message_sender.send('FSM', 'Entered state 3!')
def on_enter_4(self, event_data):
self.message_sender.send('FSM', 'Entered state 4!')
def on_enter_5(self, event_data):
self.message_sender.send('FSM', 'Entered state 5!')