diff --git a/doomdarkages/doomdarkages.py b/doomdarkages/doomdarkages.py index ca283c9..fcb4276 100644 --- a/doomdarkages/doomdarkages.py +++ b/doomdarkages/doomdarkages.py @@ -6,7 +6,6 @@ import os.path import time import sys import pydirectinput as user -import re from doomdarkages_utils import get_resolution sys.path.insert(1, os.path.join(sys.path[0], "..")) @@ -41,18 +40,15 @@ def start_game(): return exec_steam_game(STEAM_GAME_ID, game_params=["+com_skipIntroVideo", "1"]) def find_latest_result_file(base_path): - """Look for files in the benchmark results path that match the pattern in the regular expression""" + """Look for files in the benchmark results path that match the pattern. + Returns the most recent benchmark file.""" base_path = Path(base_path) - try: - return max( - base_path.glob("benchmark-*.json"), - key=lambda p: p.stat().st_mtime - ) - except ValueError: - raise FileNotFoundError( - f"No benchmark-*.json files found in {base_path}" - ) + files = list(base_path.glob("benchmark-*.json")) + if not files: + raise ValueError(f"No benchmark-*.json files found in {base_path}") + + return max(files, key=lambda p: p.stat().st_mtime) def run_benchmark(): """Runs the actual benchmark.""" diff --git a/doomdarkages/doomdarkages_utils.py b/doomdarkages/doomdarkages_utils.py index 8d16513..1377137 100644 --- a/doomdarkages/doomdarkages_utils.py +++ b/doomdarkages/doomdarkages_utils.py @@ -24,9 +24,15 @@ def get_resolution() -> tuple[int, int]: RUN_DIR.glob("benchmark-*.json"), key=lambda p: p.stat().st_mtime ) - except ValueError: - raise FileNotFoundError(f"No benchmark-*.json files in {RUN_DIR}") + except ValueError as exc: + # No files matched, propagate as a clearer FileNotFoundError + raise FileNotFoundError( + f"No benchmark-*.json files in {RUN_DIR}" + ) from exc + if not bench_file.is_file(): + raise FileNotFoundError(f"Benchmark file not found.") + with bench_file.open(encoding="utf-8") as f: data = json.load(f) @@ -54,4 +60,3 @@ def copy_launcher_config() -> None: except OSError as err: logging.error("Could not copy config file.") raise err -