mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-10 18:07:07 +01:00
Deterministically cover the SteamAPIError branch in stats refresh
The `except SteamAPIError` branch in _refresh_recently_played_completions was only covered incidentally, by cmd_stats tests that make a real network call which fails — reachable only under certain pytest-randomly orderings, so CI's 100% coverage gate flaked (missing _stats.py 368-370). Add a focused test that mocks SteamAPIClient.get_owned_games to raise SteamAPIError, covering the branch reliably regardless of order or network. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RRCdR4D8SaVrN2xraMQxM
This commit is contained in:
parent
0c48ed022c
commit
27c637c009
@ -21,7 +21,7 @@ from steam_backlog_enforcer._stats import (
|
||||
from steam_backlog_enforcer._web_dataset import PaceVsHLTB
|
||||
from steam_backlog_enforcer.config import Config, State
|
||||
from steam_backlog_enforcer.protondb import ProtonDBRating
|
||||
from steam_backlog_enforcer.steam_api import GameInfo
|
||||
from steam_backlog_enforcer.steam_api import GameInfo, SteamAPIError
|
||||
|
||||
_PKG = "steam_backlog_enforcer._stats"
|
||||
|
||||
@ -990,6 +990,24 @@ class TestRefreshRecentlyPlayedCompletions:
|
||||
result = _refresh_recently_played_completions(games, Config())
|
||||
assert result == games
|
||||
|
||||
def test_steam_api_error_returns_games_unchanged(self) -> None:
|
||||
"""A SteamAPIError while fetching owned games is swallowed."""
|
||||
games = [GameInfo(1, "G", 10, 0, 60)]
|
||||
with (
|
||||
patch(f"{_PKG}.SNAPSHOT_FILE") as mock_sf,
|
||||
patch(f"{_PKG}.SteamAPIClient") as mock_cls,
|
||||
):
|
||||
mock_sf.stat.return_value.st_mtime = 1_000_000.0
|
||||
mock_cls.return_value.get_owned_games.side_effect = SteamAPIError(
|
||||
"api down"
|
||||
)
|
||||
from steam_backlog_enforcer._stats import (
|
||||
_refresh_recently_played_completions,
|
||||
)
|
||||
|
||||
result = _refresh_recently_played_completions(games, Config())
|
||||
assert result == games
|
||||
|
||||
def test_no_recently_played_returns_games_unchanged(self) -> None:
|
||||
games = [GameInfo(1, "G", 10, 0, 60)]
|
||||
with (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user