Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AttackingOrDefending authored Feb 6, 2024
1 parent f450a4c commit caa4ae6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import time
import random
import math
import sys
import test_bot.lichess
from collections import Counter
from collections.abc import Callable
Expand Down Expand Up @@ -597,10 +598,10 @@ def getHomemadeEngine(name: str) -> type[MinimalEngine]:
from lib import strategies
from test_bot import strategies as test_strategies
engine: type[MinimalEngine]
if __name__ == "main":
engine = getattr(strategies, name)
else:
if hasattr(sys, '_called_from_test'):
engine = getattr(test_strategies, name)
else:
engine = getattr(strategies, name)
return engine


Expand Down
6 changes: 2 additions & 4 deletions lichess-bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import chess
import chess.pgn
from chess.variant import find_variant
from lib import engine_wrapper, model, matchmaking, lichess
from lib import engine_wrapper, model, lichess, matchmaking
import json
import logging
import logging.handlers
Expand Down Expand Up @@ -45,8 +45,6 @@

logger = logging.getLogger(__name__)

lichess_communicator: type[LICHESS_TYPE] = lichess.Lichess

with open("lib/versioning.yml") as version_file:
versioning_info = yaml.safe_load(version_file)

Expand Down Expand Up @@ -1025,7 +1023,7 @@ def start_lichess_bot() -> None:

max_retries = CONFIG.engine.online_moves.max_retries
check_python_version()
li = lichess_communicator(CONFIG.token, CONFIG.url, __version__, logging_level, max_retries)
li = lichess.Lichess(CONFIG.token, CONFIG.url, __version__, logging_level, max_retries)

user_profile = li.get_profile()
username = user_profile["username"]
Expand Down
10 changes: 10 additions & 0 deletions test_bot/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from typing import Any


def pytest_configure(config):
import sys
sys._called_from_test = True


def pytest_unconfigure(config):
import sys
del sys._called_from_test


def pytest_sessionfinish(session: Any, exitstatus: Any) -> None:
"""Remove files created when testing lichess-bot."""
if os.path.exists("TEMP") and not os.getenv("GITHUB_ACTIONS"):
Expand Down
5 changes: 3 additions & 2 deletions test_bot/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from lib import config
import tarfile
from lib.timer import Timer, to_seconds, seconds
import test_bot.lichess
from typing import Any
if __name__ == "__main__":
if hasattr(sys, '_called_from_test'):
sys.exit(f"The script {os.path.basename(__file__)} should only be run by pytest.")
lichess_bot = importlib.import_module("lichess-bot")

Expand Down Expand Up @@ -183,7 +184,7 @@ def run_bot(raw_config: dict[str, Any], logging_level: int, opponent_path: str =
config.insert_default_values(raw_config)
CONFIG = config.Configuration(raw_config)
lichess_bot.logger.info(lichess_bot.intro())
li = lichess_bot.test_bot.lichess.Lichess(CONFIG.token, CONFIG.url, lichess_bot.__version__, logging_level, 1)
li = test_bot.lichess.Lichess(CONFIG.token, CONFIG.url, lichess_bot.__version__, logging_level, 1)

user_profile = li.get_profile()
username = user_profile["username"]
Expand Down

0 comments on commit caa4ae6

Please sign in to comment.