mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-07-04 13:43:45 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
06c61f08bc
commit
f845273ee7
@ -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
|
||||
|
||||
@ -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."""
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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")])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user