gaia-final-assignment / tests /test_chess.py
ykumar2020's picture
Publish verified modular GAIA agent source
c641d5f verified
Raw
History Blame Contribute Delete
875 Bytes
import chess
import pytest
from tools.image_chess import best_move_san, resolve_stockfish
def test_chess_fails_closed_without_engine(monkeypatch):
monkeypatch.setattr("tools.image_chess.shutil.which", lambda _: None)
with pytest.raises(RuntimeError, match="Stockfish is required"):
resolve_stockfish(None)
def test_stockfish_move_is_converted_to_san(monkeypatch):
class Engine:
def __enter__(self):
return self
def __exit__(self, *args):
pass
def play(self, board, limit):
return type("Result", (), {"move": chess.Move.from_uci("e2e4")})()
monkeypatch.setattr(
"tools.image_chess.resolve_stockfish", lambda path=None: "stockfish"
)
monkeypatch.setattr("chess.engine.SimpleEngine.popen_uci", lambda path: Engine())
assert best_move_san(chess.STARTING_FEN) == "e4"