def test_sendMessageFromClientToServer(self): server=EchoGameServer(host,port,data_size,msghand,1) client=EchoGameClient(host,port,data_size,msghand) server.handle_connection() def eff(): client.socketStatus=False return "Nick" sys.stdin.readline = MagicMock( side_effect =eff) client.sendName() server.handle_connection() client.socketStatus=True client.sendName() client.sendMessage("_info","Message") ansS=server.handle_connection() self.assertEqual(ansS,(1, 'Nick', '_info', 'Message'))
print(message) # moves try: if typ == "move_X": stage.setX(message) stage.printStage() if typ == "move_O": stage.setO(message) stage.printStage() if typ == "stage": stage.setStage(message) stage.printStage() except (KeyError,TypeError): client.sendMessage("stage","Send all stage") # stop game if typ in ("_stop","draw"): print("\r",end="") print(message) client.close() continue if typ == "win": stage.setWinLine(int(message[5])) stage.printStage() print("\r",end="") print(message[6:]) client.close() continue
else: sys.exit() if client.status(): client.promt() while client.status(): ans = client.handle_connection() if ans: who, typ, message = ans else: continue if who=="S": if typ in ("_info","_start"): print("\r",end="") print(message) if typ =="_stop": print("\r",end="") print(message) client.close() continue else: client.sendMessage("_number",message) client.promt() print("Finish")