-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't copy files when testing #905
Conversation
I've also tried: def get_lichess():
if __name__ == "main":
from lib import lichess as lichess1
return lichess1
else: # __name__ == "lichess-bot"
from test_bot import lichess as lichess2
return lichess2 but it raises even more errors. |
Since there's only ever one instance of the # lichess-bot.py
# ...
import test_bot
# ...
LICHESS_TYPE = Union[lichess.Lichess, test_bot.lichess.Lichess]
# ...
lichess_communicator: type[LICHESS_TYPE]
if __name__ == "__main__":
lichess_communicator = lichess.Lichess
else:
lichess_communicator = test_bot.lichess.Lichess
li = lichess_communicator(CONFIG.token, CONFIG.url, __version__, logging_level, max_retries) This will require fixing the arguments and typing of the |
I do like this change. This will especially help when I'm changing lichess.py and no longer have to worry about losing changes during testing. |
Here's a hacky idea that seems to work. Change the name of the homemade class to something that wouldn't be a legal class name as a signal that this is for testing. In this case, by using hyphens in the class name. That way, users won't be able to accidentally reach the test branch. diff --git a/lib/engine_wrapper.py b/lib/engine_wrapper.py
index f64a6ec..4fe668b 100644
--- a/lib/engine_wrapper.py
+++ b/lib/engine_wrapper.py
@@ -12,7 +12,6 @@ import datetime
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 @@ class FillerEngine:
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):
+ 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 1439c54..09828a8 100644
--- a/test_bot/test_bot.py
+++ b/test_bot/test_bot.py
@@ -16,6 +16,7 @@ import tarfile
import test_bot.lichess
from lib import config
from lib.timer import Timer, to_seconds, seconds
+from lib.engine_wrapper import test_suffix
from typing import Any
if "pytest" not in sys.modules:
sys.exit(f"The script {os.path.basename(__file__)} should only be run by pytest.")
@@ -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"] = "Stockfish" + test_suffix
CONFIG["engine"]["protocol"] = "homemade"
CONFIG["pgn_directory"] = "TEMP/homemade_game_record"
win = run_bot(CONFIG, logging_level) |
Type of pull request:
Description:
Doesn't copy
test_bot\lichess.py
tolichess.py
and the back. In the past, when the tests timed out the wronglichess.py
file would be inlib/
so that the user would have to copy it back manually.strategies.py
also doesn't change in testing now.Related Issues:
None
Checklist:
Screenshots/logs (if applicable):