From f845273ee763c750afc9ee1fd797d3ab54a5234e Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Thu, 28 May 2026 21:11:53 +0200 Subject: [PATCH] fix: sort requirements.txt and add tests for uncovered branches - Move websockets after types-requests (alphabetical order for requirements-txt-fixer) - Add test for save_hltb_cache with all extras maps populated (covers _hltb_types.py:216-218) - Add test for _fetch_batch_confidence_only with truthy hp_key and pre-populated count_comp (covers hltb.py:82-83, 90->93) - Add test for count_comp_detail > 0 path in _apply_detail_to_extras (covers _hltb_detail.py:254) Co-Authored-By: Claude Sonnet 4.6 --- requirements.txt | 2 +- steam_backlog_enforcer/tests/test_hltb.py | 18 +++++++++++++ .../tests/test_hltb_detail.py | 25 ++++++++++++++++++ .../tests/test_hltb_part2.py | 26 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ea3ed3d..04a8ee8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,5 @@ pytest-timeout>=2.2.0 pytest-xdist>=3.5.0 requests>=2.0 ruff>=0.8.0 -websockets>=12.0 types-requests>=2.31.0 +websockets>=12.0 diff --git a/steam_backlog_enforcer/tests/test_hltb.py b/steam_backlog_enforcer/tests/test_hltb.py index 77a12ae..cb33e75 100644 --- a/steam_backlog_enforcer/tests/test_hltb.py +++ b/steam_backlog_enforcer/tests/test_hltb.py @@ -66,6 +66,24 @@ class TestHltbCache: ): save_hltb_cache({440: 10.5}) # Should not raise + def test_save_cache_full_extras_skips_existing_read(self, tmp_path: Path) -> None: + from steam_backlog_enforcer._hltb_types import _HLTBExtras + + cache_file = tmp_path / "hltb_cache.json" + extras = _HLTBExtras( + hltb_game_id={440: 1}, + rush={440: 5.0}, + leisure_100h={440: 20.0}, + ) + with ( + patch("steam_backlog_enforcer._hltb_types.HLTB_CACHE_FILE", cache_file), + patch("steam_backlog_enforcer._hltb_types.CONFIG_DIR", tmp_path), + patch("steam_backlog_enforcer._hltb_types._read_raw_cache") as mock_read, + ): + save_hltb_cache({440: 10.5}, extras=extras) + mock_read.assert_not_called() + assert cache_file.exists() + class TestGetHltbSearchUrl: """Tests for _get_hltb_search_url.""" diff --git a/steam_backlog_enforcer/tests/test_hltb_detail.py b/steam_backlog_enforcer/tests/test_hltb_detail.py index 3b9c6b8..570c23b 100644 --- a/steam_backlog_enforcer/tests/test_hltb_detail.py +++ b/steam_backlog_enforcer/tests/test_hltb_detail.py @@ -565,3 +565,28 @@ class TestFetchLeisureTimes: ): asyncio.run(_fetch_leisure_times(results, cache, {}, None, extras=extras)) assert cache[440] == 1.0 + + def test_count_comp_from_detail_page_stored_in_extras(self) -> None: + """Line 254: extras.count_comp updated when game detail has count_comp > 0.""" + results = [ + HLTBResult( + app_id=440, + game_name="TF2", + completionist_hours=50.0, + similarity=1.0, + hltb_game_id=12345, + ), + ] + game_data: dict[str, Any] = { + "game": [{"comp_100_h": 3600, "count_comp": 99}], + "relationships": [], + } + cache: dict[int, float] = {} + extras = _HLTBExtras() + with patch( + "steam_backlog_enforcer._hltb_detail._fetch_detail_one", + new_callable=AsyncMock, + return_value=game_data, + ): + asyncio.run(_fetch_leisure_times(results, cache, {}, None, extras=extras)) + assert extras.count_comp[440] == 99 diff --git a/steam_backlog_enforcer/tests/test_hltb_part2.py b/steam_backlog_enforcer/tests/test_hltb_part2.py index 77b12ba..2bc6e18 100644 --- a/steam_backlog_enforcer/tests/test_hltb_part2.py +++ b/steam_backlog_enforcer/tests/test_hltb_part2.py @@ -214,6 +214,32 @@ class TestConfidenceHelpers: assert result == [] mock_search.assert_called_once() + def test_fetch_batch_confidence_only_with_hp_key_and_prepopulated_count_comp( + self, + ) -> None: + auth_token = str(1) + with ( + patch(f"{PKG}.aiohttp.ClientSession", return_value=_DummySession()), + patch(f"{PKG}.aiohttp.TCPConnector"), + patch(f"{PKG}._get_hltb_search_url", return_value="https://example"), + patch( + f"{PKG}._get_auth_info", + return_value=_AuthInfo(token=auth_token, hp_key="hpk", hp_val="hpv"), + ), + patch(f"{PKG}._search_one", side_effect=[None]) as mock_search, + ): + result = asyncio.run( + _fetch_batch_confidence_only( + games=[(1, "Game")], + cache={}, + polls={}, + progress_cb=None, + count_comp={1: 42}, + ), + ) + assert result == [] + mock_search.assert_called_once() + def test_fetch_hltb_confidence_initializes_optional_dicts(self) -> None: with patch(f"{PKG}.asyncio.run", return_value=[]) as mock_run: result = fetch_hltb_confidence([(1, "Game")])