Skip to content

Commit c1ee6f3

Browse files
francoijsnicolodavis
authored andcommitted
python bot: fix #379 (#380)
- replace unmaintained dependency socketIO_client with socketIO_client_nexus - handle new message 'update'
1 parent a34c036 commit c1ee6f3

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

python/boardgameio.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313

1414
import logging
15-
import socketIO_client as io
15+
import socketIO_client_nexus as io
1616

1717
class Namespace(io.BaseNamespace):
1818
"""
@@ -47,8 +47,12 @@ def on_reconnect(self):
4747
""" Handle reconnection event. """
4848
self.log.info('reconnected')
4949

50+
def on_update(self, *args):
51+
""" Handle server 'update' event. """
52+
self.on_sync(*args)
53+
5054
def on_sync(self, *args):
51-
""" Handle serve 'sync' event. """
55+
""" Handle server 'sync' event. """
5256
game_id = args[0]
5357
state = args[1]
5458
state_id = state['_stateID']
@@ -77,7 +81,7 @@ def on_sync(self, *args):
7781
# pop next action
7882
action = self.actions.pop(0)
7983
self.log.info('sent action: %s', action['payload'])
80-
self.emit('action', action, state_id, game_id,
84+
self.emit('update', action, state_id, game_id,
8185
self.bot.player_id)
8286

8387

@@ -144,11 +148,11 @@ def think(self, _G, _ctx):
144148
To be overridden by the user.
145149
Shall return a list of actions, instantiated with make_move().
146150
"""
147-
assert False
151+
raise NotImplementedError
148152

149153
def gameover(self, _G, _ctx):
150154
"""
151155
To be overridden by the user.
152156
Shall handle game over.
153157
"""
154-
assert False
158+
raise NotImplementedError

python/test_boardgameio.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import unittest
1717
import logging
1818
import mock
19-
import socketIO_client as io
19+
import socketIO_client_nexus as io
2020
from boardgameio import Namespace, Bot
2121

2222

@@ -46,7 +46,15 @@ def test_on_sync_shall_call_think(self):
4646
# call Namespace.on_sync()
4747
self.sut.on_sync(self.botmock.game_id, self.game_state)
4848
self.botmock.think.assert_called_once_with(self.game_state['G'], self.game_state['ctx'])
49-
self.sut.emit.assert_called_once_with('action', self.resulting_move,
49+
self.sut.emit.assert_called_once_with('update', self.resulting_move,
50+
self.game_state['_stateID'],
51+
self.botmock.game_id, self.botmock.player_id)
52+
53+
def test_on_update_shall_call_think(self):
54+
# call Namespace.on_update()
55+
self.sut.on_update(self.botmock.game_id, self.game_state)
56+
self.botmock.think.assert_called_once_with(self.game_state['G'], self.game_state['ctx'])
57+
self.sut.emit.assert_called_once_with('update', self.resulting_move,
5058
self.game_state['_stateID'],
5159
self.botmock.game_id, self.botmock.player_id)
5260

0 commit comments

Comments
 (0)