test: the branches the Qodana fixes touched

SonarCloud's gate wants 80% coverage on new code, and the PR's changed
lines were at 71.8%: ten of them were never run by a test. Now they are:

- appdetails' failures told apart (no answer, 404, success: false, a
  body that is not JSON) and the store page's two network_error paths;
- the leaderboards' stars, for a percentage and for "N/A", "No reviews"
  and a missing field (both scripts);
- mark_dead_games.parse_players() on the stored formatted strings;
- backfill_discover.parse_released() on every date shape, the year-only
  one included.

pytest: 501 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5.5 committed 2026-11-17 08:54:28 +07:00
1 parent 55fcf1342a
commit c9e133d3ef
4 files changed
+96

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
"""
The backfill buckets each search row by its release date as the store search
writes it (asked with l=english, so the month names are English).
Run from the repository root: python -m pytest scripts/tests
"""
import pytest
from backfill_discover import parse_released
@pytest.mark.parametrize("text, expected", [
("21 Aug, 2012", (2012, 8)),
("Aug 21, 2012", (2012, 8)),
("Sep 2024", (2024, 9)),
# A year alone sorts with the year's start.
("2025", (2025, 1)),
# Not dates: kept out of every window.
("Xyz 2024", None),
("Q1 2026", None),
("Coming soon", None),
("", None),
(None, None),
])
def test_release_rows_are_bucketed_by_year_and_month(text, expected):
assert parse_released(text) == expected
+14
View File
@@ -74,3 +74,17 @@ def test_update_data_refills_only_incomplete_records(repo):
repo.setattr(fetcher, "fetch_full", lambda g, client=None, guard=None: refilled.append(g["link"])) repo.setattr(fetcher, "fetch_full", lambda g, client=None, guard=None: refilled.append(g["link"]))
update_data.main() update_data.main()
assert len(refilled) == 3 # the fixture's records lack most store fields assert len(refilled) == 3 # the fixture's records lack most store fields
@pytest.mark.parametrize("module", [top_online, top_offline])
@pytest.mark.parametrize("reviews, stars", [
("96% (Overwhelmingly Positive)", "★★★★★"),
("72% (Mostly Positive)", "★★★☆☆"),
("12% (Overwhelmingly Negative)", "★☆☆☆☆"),
# Never read, no reviews, or no field at all: no stars, and no crash.
("N/A", "—"),
("No reviews", "—"),
(None, "—"),
])
def test_stars_come_from_the_percentage_and_nothing_else(module, reviews, stars):
assert module._stars(reviews) == stars
+22
View File
@@ -0,0 +1,22 @@
"""
mark_dead_games.py compares player counts, which the dataset stores as
formatted strings ("492,197"), never as numbers (CLAUDE.md).
Run from the repository root: python -m pytest scripts/tests
"""
import pytest
from mark_dead_games import parse_players
@pytest.mark.parametrize("stored, players", [
("492,197", 492197),
("0", 0),
(12, 12),
(3.0, 3),
(None, 0),
("N/A", 0),
("", 0),
])
def test_players_are_read_from_the_stored_string(stored, players):
assert parse_players(stored) == players
+34
View File
@@ -181,3 +181,37 @@ def test_tag_names_are_fetched_once():
assert client.fetch_tag_names() == {12095: "Sexual Content"} assert client.fetch_tag_names() == {12095: "Sexual Content"}
assert len(session.requests) == 1 assert len(session.requests) == 1
assert session.requests[0]["params"] == {"language": "english"} assert session.requests[0]["params"] == {"language": "english"}
APPDETAILS = "https://store.steampowered.com/api/appdetails"
class _NotJson(_Resp):
def json(self):
raise ValueError("Expecting value")
@pytest.mark.parametrize("answer, expected", [
# A 403 is no answer at all: _get gives up on it and hands back nothing.
(_Resp(APPDETAILS, status_code=403), ("network_error", None)),
(_Resp(APPDETAILS, status_code=404), ("not_found", None)),
# What purge asks again before it believes it (RECHECK_AFTER).
(_Resp(APPDETAILS, body={"10": {"success": False}}), ("unavailable", None)),
(_NotJson(APPDETAILS), ("network_error", None)),
])
def test_appdetails_tells_its_failures_apart(answer, expected):
client, _ = _client(answer)
assert client.fetch_app_details_full("10") == expected
def test_a_store_page_nobody_answered_is_a_network_error():
client, _ = _client(_Resp(APP, status_code=403))
assert client.fetch_store_page_full("2279510") == ("network_error", None)
def test_a_store_page_answer_neither_200_nor_404_is_a_network_error(monkeypatch):
# _get hands back only a 200 or a 404/410 today; the page does not lean on that.
client, _ = _client()
# SteamClient has __slots__: the method is replaced on the class, for this test only.
monkeypatch.setattr(SteamClient, "_get", lambda self, *args, **kwargs: _Resp(APP, status_code=302))
assert client.fetch_store_page_full("2279510") == ("network_error", None)