mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:11:33 +00:00
Add cenerator to enable testing
This commit is contained in:
parent
2530fe43ea
commit
dbc2d1c0ea
@ -1,7 +1,18 @@
|
|||||||
|
from itertools import cycle
|
||||||
|
|
||||||
from tfw.networking.serialization import deserialize_all
|
from tfw.networking.serialization import deserialize_all
|
||||||
from tfw.networking.event_handlers.server_connector import ServerConnector
|
from tfw.networking.event_handlers.server_connector import ServerConnector
|
||||||
|
|
||||||
|
|
||||||
|
def cenator():
|
||||||
|
yield from [
|
||||||
|
'**Your time is up**',
|
||||||
|
'`My time is now`',
|
||||||
|
'_You can\'t see me_',
|
||||||
|
'My time is now'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class EventHandlerBase:
|
class EventHandlerBase:
|
||||||
def __init__(self, anchor):
|
def __init__(self, anchor):
|
||||||
self.server_connector = ServerConnector()
|
self.server_connector = ServerConnector()
|
||||||
@ -10,9 +21,13 @@ class EventHandlerBase:
|
|||||||
self.subscribe(self.anchor)
|
self.subscribe(self.anchor)
|
||||||
self.subscribe('reset')
|
self.subscribe('reset')
|
||||||
self.server_connector.register_callback(self.event_handler_callback)
|
self.server_connector.register_callback(self.event_handler_callback)
|
||||||
|
self.cenerator = cycle(cenator())
|
||||||
|
|
||||||
def event_handler_callback(self, msg_parts):
|
def event_handler_callback(self, msg_parts):
|
||||||
anchor, message = deserialize_all(*msg_parts)
|
anchor, message = deserialize_all(*msg_parts)
|
||||||
|
from .message_sender import MessageSender
|
||||||
|
ms = MessageSender()
|
||||||
|
ms.send('JOHN CENA', next(self.cenerator))
|
||||||
response = self.handle_event(anchor, message) if anchor != 'reset' else self.handle_reset(message)
|
response = self.handle_event(anchor, message) if anchor != 'reset' else self.handle_reset(message)
|
||||||
if response is None: return
|
if response is None: return
|
||||||
self.server_connector.send(anchor, response)
|
self.server_connector.send(anchor, response)
|
||||||
|
Loading…
Reference in New Issue
Block a user