From 772b4ab426b3f4618f375b72651d634b138dff16 Mon Sep 17 00:00:00 2001 From: Ioannis Pantidis <40605232+AttackingOrDefending@users.noreply.github.com> Date: Thu, 8 Feb 2024 20:40:01 +0200 Subject: [PATCH] Add files via upload --- lib/engine_wrapper.py | 8 +++++--- test_bot/test_bot.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/engine_wrapper.py b/lib/engine_wrapper.py index f64a6ec12..c0a202f84 100644 --- a/lib/engine_wrapper.py +++ b/lib/engine_wrapper.py @@ -12,7 +12,6 @@ import time import random import math -import sys import test_bot.lichess from collections import Counter from collections.abc import Callable @@ -588,6 +587,9 @@ def method(*args: Any, **kwargs: Any) -> Any: return method +test_suffix = "-for-lichess-bot-testing-only" + + def getHomemadeEngine(name: str) -> type[MinimalEngine]: """ Get the homemade engine with name `name`. e.g. If `name` is `RandomMove` then we will return `strategies.RandomMove`. @@ -598,8 +600,8 @@ def getHomemadeEngine(name: str) -> type[MinimalEngine]: from lib import strategies from test_bot import strategies as test_strategies engine: type[MinimalEngine] - if "pytest" in sys.modules: - engine = getattr(test_strategies, name) + if name.endswith(test_suffix): # Test only. + engine = getattr(test_strategies, name.removesuffix(test_suffix)) else: engine = getattr(strategies, name) return engine diff --git a/test_bot/test_bot.py b/test_bot/test_bot.py index 1439c5449..9b2bc25b3 100644 --- a/test_bot/test_bot.py +++ b/test_bot/test_bot.py @@ -17,6 +17,7 @@ from lib import config from lib.timer import Timer, to_seconds, seconds from typing import Any +from lib.engine_wrapper import test_suffix if "pytest" not in sys.modules: sys.exit(f"The script {os.path.basename(__file__)} should only be run by pytest.") lichess_bot = importlib.import_module("lichess-bot") @@ -292,7 +293,7 @@ def test_homemade() -> None: with open("./config.yml.default") as file: CONFIG = yaml.safe_load(file) CONFIG["token"] = "" - CONFIG["engine"]["name"] = "Stockfish" + CONFIG["engine"]["name"] = f"Stockfish{test_suffix}" CONFIG["engine"]["protocol"] = "homemade" CONFIG["pgn_directory"] = "TEMP/homemade_game_record" win = run_bot(CONFIG, logging_level)