Files
SteamBase/tests/test_hltb.py
T
2026-11-07 00:13:21 +03:00

55 lines
2.1 KiB
Python

"""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_matches_case_roman_and_editions(self):
cases = [
("SOMA", "Soma"),
("INSIDE", "Inside"),
("Divinity: Original Sin 2", "Divinity: Original Sin II"),
("Stronghold Crusader HD", "Stronghold: Crusader"),
("Batman: Arkham Asylum GOTY Edition", "Batman: Arkham Asylum"),
("STAR WARS™ Republic Commando", "Star Wars: Republic Commando"),
("Age of Empires II (2013)", "Age of Empires II"),
("Dishonored RHCP", "Dishonored"),
("Serious Sam Classic: The First Encounter", "Serious Sam: The First Encounter"),
]
for query, title in cases:
entry = SimpleNamespace(game_name=title)
self.assertIs(fetch_hltb.find_match([entry], query), entry)
def test_search_variants_include_year(self):
variants = fetch_hltb.search_variants("DOOM", 2016)
self.assertIn("doom", variants)
self.assertIn("doom 2016", variants)
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()