From 27c637c0091cd6db249c8e58c0e21e751ab0c488 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 10 Jul 2026 23:10:44 +0200 Subject: [PATCH] Deterministically cover the SteamAPIError branch in stats refresh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Claude-Session: https://claude.ai/code/session_017RRCdR4D8SaVrN2xraMQxM --- steam_backlog_enforcer/tests/test_stats.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/steam_backlog_enforcer/tests/test_stats.py b/steam_backlog_enforcer/tests/test_stats.py index cf5e6e8..5211e8a 100644 --- a/steam_backlog_enforcer/tests/test_stats.py +++ b/steam_backlog_enforcer/tests/test_stats.py @@ -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 (