Skip to content

Commit f4d7352

Browse files
committed
Tests for sending game result
1 parent ee210f4 commit f4d7352

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

test.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,6 +3664,80 @@ async def main():
36643664
asyncio.set_event_loop_policy(chess.engine.EventLoopPolicy())
36653665
asyncio.run(main())
36663666

3667+
def test_xboard_result(self):
3668+
async def main():
3669+
protocol = chess.engine.XBoardProtocol()
3670+
mock = chess.engine.MockTransport(protocol)
3671+
3672+
mock.expect("xboard")
3673+
mock.expect("protover 2", ["feature ping=1 setboard=1 done=1"])
3674+
await protocol.initialize()
3675+
mock.assert_done()
3676+
3677+
limit = chess.engine.Limit(time=5)
3678+
checkmate_board = chess.Board("k7/7R/6R1/8/8/8/8/K7 w - - 0 1")
3679+
3680+
mock.expect("new")
3681+
mock.expect("force")
3682+
mock.expect("setboard k7/7R/6R1/8/8/8/8/K7 w - - 0 1")
3683+
mock.expect("st 5")
3684+
mock.expect("nopost")
3685+
mock.expect("easy")
3686+
mock.expect("go", ["move g6g8"])
3687+
mock.expect_ping()
3688+
mock.expect("force")
3689+
mock.expect("result 1-0 {White mates}")
3690+
result = await protocol.play(checkmate_board, limit, game="checkmate")
3691+
self.assertEqual(result.move, checkmate_board.parse_uci("g6g8"))
3692+
checkmate_board.push(result.move)
3693+
self.assertTrue(checkmate_board.is_checkmate())
3694+
await protocol.send_game_result(checkmate_board)
3695+
mock.assert_done()
3696+
3697+
unfinished_board = chess.Board()
3698+
mock.expect("new")
3699+
mock.expect("force")
3700+
mock.expect("st 5")
3701+
mock.expect("nopost")
3702+
mock.expect("easy")
3703+
mock.expect("go", ["move e2e4"])
3704+
mock.expect_ping()
3705+
mock.expect("force")
3706+
mock.expect("result *")
3707+
result = await protocol.play(unfinished_board, limit, game="unfinished")
3708+
self.assertEqual(result.move, unfinished_board.parse_uci("e2e4"))
3709+
unfinished_board.push(result.move)
3710+
await protocol.send_game_result(unfinished_board, game_complete=False)
3711+
mock.assert_done()
3712+
3713+
timeout_board = chess.Board()
3714+
mock.expect("new")
3715+
mock.expect("force")
3716+
mock.expect("st 5")
3717+
mock.expect("nopost")
3718+
mock.expect("easy")
3719+
mock.expect("go", ["move e2e4"])
3720+
mock.expect_ping()
3721+
mock.expect("force")
3722+
mock.expect("result 0-1 {Time forfeiture}")
3723+
result = await protocol.play(timeout_board, limit, game="timeout")
3724+
self.assertEqual(result.move, timeout_board.parse_uci("e2e4"))
3725+
timeout_board.push(result.move)
3726+
await protocol.send_game_result(timeout_board, chess.BLACK, "Time forfeiture")
3727+
mock.assert_done()
3728+
3729+
material_board = chess.Board("k7/8/8/8/8/8/8/K7 b - - 0 1")
3730+
self.assertTrue(material_board.is_insufficient_material())
3731+
mock.expect("new")
3732+
mock.expect("force")
3733+
mock.expect("setboard k7/8/8/8/8/8/8/K7 b - - 0 1")
3734+
mock.expect("result 1/2-1/2 {Insufficient material}")
3735+
await protocol.send_game_result(material_board)
3736+
mock.assert_done()
3737+
3738+
asyncio.set_event_loop_policy(chess.engine.EventLoopPolicy())
3739+
asyncio.run(main())
3740+
36673741
def test_xboard_analyse(self):
36683742
async def main():
36693743
protocol = chess.engine.XBoardProtocol()

0 commit comments

Comments
 (0)