File size: 875 Bytes
c641d5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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"
|