feat: add optional HLTB enrichment
CI / test (push) Successful in 7m10s

This commit is contained in:
strsv committed 2026-11-06 22:16:27 +03:00
1 parent b865a4a389
commit d07dec5e75
19 files changed
+258 -23

No files matched your search

+3
View File
@@ -104,6 +104,8 @@ class ApiTests(unittest.TestCase):
con.execute("INSERT INTO attributes (appid, key, value) VALUES (1, 'mood', 'calm')")
con.execute("""UPDATE games SET estimated_hours = CASE appid
WHEN 1 THEN 30 WHEN 2 THEN 10 WHEN 3 THEN 5 ELSE NULL END""")
con.execute("""UPDATE games SET hltb_main = 23.5, hltb_extra = 30.0,
hltb_complete = 50.0 WHERE appid = 1""")
con.commit()
def get(self, path, expect=200):
@@ -341,6 +343,7 @@ class ApiTests(unittest.TestCase):
self.assertEqual(data["size_gb"], 1.0)
self.assertEqual(data["steam_url"], "https://store.steampowered.com/app/1/")
self.assertEqual(data["attributes"], [{"key": "mood", "value": "calm"}])
self.assertEqual(data["hltb"], {"main": 23.5, "extra": 30.0, "complete": 50.0})
self.assertTrue(data["similar"])
self.assertEqual(data["similar"][0]["appid"], 2)
+4
View File
@@ -68,6 +68,8 @@ class SchemaVersionTests(unittest.TestCase):
self.assertIn("reco_feedback", tables)
self.assertIn("game_fts", tables)
self.assertIn("estimated_hours", self._columns(con, "games"))
self.assertIn("hltb_main", self._columns(con, "games"))
self.assertIn("hltb_complete", self._columns(con, "games"))
def test_legacy_database_is_migrated_and_data_preserved(self):
con = sqlite3.connect(self.path)
@@ -89,6 +91,8 @@ class SchemaVersionTests(unittest.TestCase):
self.assertEqual(details["short_description"], "Old description")
self.assertIsNone(details["source_appid"])
self.assertIn("estimated_hours", self._columns(con, "games"))
self.assertIn("hltb_main", self._columns(con, "games"))
self.assertIn("hltb_complete", self._columns(con, "games"))
fts_tables = {r[0] for r in con.execute(
"SELECT name FROM sqlite_master WHERE name='game_fts'")}
self.assertEqual(fts_tables, {"game_fts"})
+33
View File
@@ -0,0 +1,33 @@
"""Tests for the optional HLTB enrichment helpers."""
import os
import sys
import unittest
from types import SimpleNamespace
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(ROOT, "tools"))
import fetch_hltb
class HltbTests(unittest.TestCase):
def test_normalize(self):
self.assertEqual(fetch_hltb.normalize("Hades™ (R)"), "hades")
self.assertEqual(fetch_hltb.normalize("Half-Life 2"), "half life 2")
self.assertEqual(fetch_hltb.normalize(""), "")
def test_find_exact_match_only(self):
entries = [SimpleNamespace(game_name="Hades"), SimpleNamespace(game_name="Hades II")]
self.assertEqual(fetch_hltb.find_match(entries, "hades").game_name, "Hades")
self.assertIsNone(fetch_hltb.find_match(entries, "Hade"))
def test_positive(self):
self.assertEqual(fetch_hltb.positive("23.5"), 23.5)
self.assertIsNone(fetch_hltb.positive(0))
self.assertIsNone(fetch_hltb.positive("n/a"))
self.assertIsNone(fetch_hltb.positive(None))
if __name__ == "__main__":
unittest.main()