diff --git a/tests/instrumented.py b/tests/instrumented.py index bb7efa80913..a3747d4e97a 100644 --- a/tests/instrumented.py +++ b/tests/instrumented.py @@ -254,7 +254,7 @@ def test_depth_5_with_callback(self): self.stockfish.send_command("go depth 5") def callback(output): - regex = "info depth \d+ seldepth \d+ multipv \d+ score cp \d+ nodes \d+ nps \d+ hashfull \d+ tbhits \d+ time \d+ pv" + regex = r"info depth \d+ seldepth \d+ multipv \d+ score cp \d+ nodes \d+ nps \d+ hashfull \d+ tbhits \d+ time \d+ pv" if output.startswith("info depth") and not re.match(regex, output): assert False if output.startswith("bestmove"): @@ -274,7 +274,7 @@ def test_ucinewgame_and_go_depth_9(self): def callback(output): nonlocal depth - regex = f"info depth {depth} seldepth \d+ multipv \d+ score cp \d+ wdl \d+ \d+ \d+ nodes \d+ nps \d+ hashfull \d+ tbhits \d+ time \d+ pv" + regex = rf"info depth {depth} seldepth \d+ multipv \d+ score cp \d+ wdl \d+ \d+ \d+ nodes \d+ nps \d+ hashfull \d+ tbhits \d+ time \d+ pv" if output.startswith("info depth"): if not re.match(regex, output): diff --git a/tests/testing.py b/tests/testing.py index 3034ac737f0..d51ca89ac92 100644 --- a/tests/testing.py +++ b/tests/testing.py @@ -1,5 +1,5 @@ import subprocess -from typing import List, Callable, Any +from typing import List import os import collections import time @@ -10,10 +10,11 @@ from contextlib import redirect_stdout import io import tarfile -import urllib.request import pathlib import concurrent.futures import tempfile +import shutil +import requests CYAN_COLOR = "\033[36m" GRAY_COLOR = "\033[2m" @@ -90,15 +91,20 @@ def get_syzygy_path(): def download_syzygy(): if not os.path.isdir(os.path.join(PATH, "syzygy")): url = "https://api.github.com/repos/niklasf/python-chess/tarball/9b9aa13f9f36d08aadfabff872882f4ab1494e95" - tarball_path = "/tmp/python-chess.tar.gz" + file = "niklasf-python-chess-9b9aa13" - urllib.request.urlretrieve(url, tarball_path) + with tempfile.TemporaryDirectory() as tmpdirname: + tarball_path = os.path.join(tmpdirname, f"{file}.tar.gz") - with tarfile.open(tarball_path, "r:gz") as tar: - tar.extractall("/tmp") + response = requests.get(url, stream=True) + with open(tarball_path, 'wb') as f: + for chunk in response.iter_content(chunk_size=8192): + f.write(chunk) - os.rename("/tmp/niklasf-python-chess-9b9aa13", os.path.join(PATH, "syzygy")) + with tarfile.open(tarball_path, "r:gz") as tar: + tar.extractall(tmpdirname) + shutil.move(os.path.join(tmpdirname, file), os.path.join(PATH, "syzygy")) class OrderedClassMembers(type): @classmethod