34 lines
1.1 KiB
Python
34 lines
1.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_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()
|