def test_controller_protocol1(self): eng = MockEngine(protocol1) ctl = EngineController(eng) self.assertEqual(ctl.ident["name"], "Mock") self.assertEqual(ctl.ident["author"], "Janzert") self.assertEqual(ctl.protocol_version, 1) self.assertEqual(ctl.is_running(), True) resp = ctl.get_response() self.assertIsInstance(resp, EngineResponse) self.assertEqual(resp.type, "log") self.assertEqual(resp.message, eng.expected[eng.event - 1][1].lstrip("log ")) ctl.setoption("depth", 4) ctl.newgame() pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP) ctl.setposition(pos) ctl.go() ctl.stop() resp = ctl.get_response() self.assertEqual(resp.type, "info") self.assertEqual(resp.message, eng.expected[eng.event - 1][1].lstrip("info ")) resp = ctl.get_response() self.assertEqual(resp.type, "bestmove") self.assertEqual(resp.move, eng.expected[eng.event - 1][1].lstrip("bestmove ")) ctl.makemove("Hb2n Ed2n") ctl.go("ponder") ctl.quit() ctl.cleanup()
def test_controller(self): eng = MockEngine(protocol1) ctl = EngineController(eng) self.assertEqual(ctl.ident["name"], "Mock") self.assertEqual(ctl.ident["author"], "Janzert") self.assertEqual(ctl.protocol_version, 1) self.assertEqual(ctl.is_running(), True) self.assertRaises(socket.timeout, ctl.get_response) resp = ctl.get_response() self.assertIsInstance(resp, EngineResponse) self.assertEqual(resp.type, "log") self.assertEqual(resp.message, eng.expected[eng.event - 1][1].lstrip("log ")) ctl.setoption("depth", 4) ctl.newgame() pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP) ctl.setposition(pos) ctl.go() ctl.stop() resp = ctl.get_response() self.assertEqual(resp.type, "info") self.assertEqual(resp.message, eng.expected[eng.event - 1][1].lstrip("info ")) resp = ctl.get_response() self.assertEqual(resp.type, "bestmove") self.assertEqual(resp.move, eng.expected[eng.event - 1][1].lstrip("bestmove ")) ctl.makemove("Hb2n Ed2n") ctl.go("ponder") ctl.quit() ctl.cleanup() # bad response to isready eng = MockEngine(bad_isready_response) ctl = EngineController(eng) ctl.newgame() self.assertRaises(EngineException, ctl.isready) # timeout waiting for aeiok eng = MockEngine(aeiok_timeout) self.assertRaises(EngineException, EngineController, eng) # IOError sending aei eng = MockEngine(aei_send_error) self.assertRaises(EngineException, EngineController, eng)