steam-backlog-enforcer/steam_backlog_enforcer/tests/_protondb_cache.py
Krzysztof kuhy Rudnicki d2565416aa Pylint gate covers tests, no suppressions
Tests are now linted by the 10.00 gate (ignore-paths dropped), with no
per-test disables. CtlServer/DaemonControl members the tests drive are
public (renamed, behaviour unchanged); SteamAPIClient._get takes its
params explicitly, as every caller already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:17:07 +01:00

36 lines
1.1 KiB
Python

"""Shared ProtonDB cache-file redirection for the protondb tests."""
from __future__ import annotations
from contextlib import contextmanager
import json
from typing import TYPE_CHECKING
from unittest.mock import patch
if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path
PKG = "steam_backlog_enforcer.protondb"
def write_gold_cache(tmp_path: Path) -> Path:
"""Write a cache file rating app 440 gold and return its path."""
cache_file = tmp_path / "protondb_cache.json"
cache_file.write_text(json.dumps({"440": {"tier": "gold"}}), encoding="utf-8")
return cache_file
@contextmanager
def cache_at(cache_file: Path) -> Iterator[None]:
"""Point the ProtonDB cache at ``cache_file`` for reads only."""
with patch(f"{PKG}.PROTONDB_CACHE_FILE", cache_file):
yield
@contextmanager
def writable_cache_at(cache_file: Path, config_dir: Path) -> Iterator[None]:
"""Point the cache file and its config dir at test paths so saves land there."""
with cache_at(cache_file), patch(f"{PKG}.CONFIG_DIR", config_dir):
yield