diff --git a/python/boardgameio.py b/python/boardgameio.py index 8130ed637..54b8f4b94 100644 --- a/python/boardgameio.py +++ b/python/boardgameio.py @@ -12,7 +12,7 @@ """ import logging -import socketIO_client as io +import socketIO_client_nexus as io class Namespace(io.BaseNamespace): """ @@ -47,8 +47,12 @@ def on_reconnect(self): """ Handle reconnection event. """ self.log.info('reconnected') + def on_update(self, *args): + """ Handle server 'update' event. """ + self.on_sync(*args) + def on_sync(self, *args): - """ Handle serve 'sync' event. """ + """ Handle server 'sync' event. """ game_id = args[0] state = args[1] state_id = state['_stateID'] @@ -77,7 +81,7 @@ def on_sync(self, *args): # pop next action action = self.actions.pop(0) self.log.info('sent action: %s', action['payload']) - self.emit('action', action, state_id, game_id, + self.emit('update', action, state_id, game_id, self.bot.player_id) @@ -144,11 +148,11 @@ def think(self, _G, _ctx): To be overridden by the user. Shall return a list of actions, instantiated with make_move(). """ - assert False + raise NotImplementedError def gameover(self, _G, _ctx): """ To be overridden by the user. Shall handle game over. """ - assert False + raise NotImplementedError diff --git a/python/test_boardgameio.py b/python/test_boardgameio.py index b2b7d7da8..090c964cd 100644 --- a/python/test_boardgameio.py +++ b/python/test_boardgameio.py @@ -16,7 +16,7 @@ import unittest import logging import mock -import socketIO_client as io +import socketIO_client_nexus as io from boardgameio import Namespace, Bot @@ -46,7 +46,15 @@ def test_on_sync_shall_call_think(self): # call Namespace.on_sync() self.sut.on_sync(self.botmock.game_id, self.game_state) self.botmock.think.assert_called_once_with(self.game_state['G'], self.game_state['ctx']) - self.sut.emit.assert_called_once_with('action', self.resulting_move, + self.sut.emit.assert_called_once_with('update', self.resulting_move, + self.game_state['_stateID'], + self.botmock.game_id, self.botmock.player_id) + + def test_on_update_shall_call_think(self): + # call Namespace.on_update() + self.sut.on_update(self.botmock.game_id, self.game_state) + self.botmock.think.assert_called_once_with(self.game_state['G'], self.game_state['ctx']) + self.sut.emit.assert_called_once_with('update', self.resulting_move, self.game_state['_stateID'], self.botmock.game_id, self.botmock.player_id)