"""Tests for M6 non-Steam game detection (Lutris SQLite + Heroic JSON).""" import json import sqlite3 import tempfile import unittest from pathlib import Path from unittest import mock from rigdoctor.core import launchers class LutrisTests(unittest.TestCase): def test_reads_installed_games_only(self): with tempfile.TemporaryDirectory() as d: db = Path(d) / "pga.db" con = sqlite3.connect(db) con.execute("CREATE TABLE games (id INTEGER, name TEXT, slug TEXT, installed INTEGER)") con.executemany( "INSERT INTO games VALUES (?, ?, ?, ?)", [(1, "Hades", "hades", 1), (2, "Hollow Knight", "hollow-knight", 1), (3, "Old Game", "old", 0)], ) con.commit() con.close() with mock.patch.object(launchers, "LUTRIS_DB", db), \ mock.patch.object(launchers, "HEROIC_DIR", Path(d) / "nope"): games = launchers.scan() names = {g.name for g in games} self.assertEqual(names, {"Hades", "Hollow Knight"}) self.assertTrue(all(g.launcher == "lutris" for g in games)) def test_missing_db_is_empty(self): with tempfile.TemporaryDirectory() as d: with mock.patch.object(launchers, "LUTRIS_DB", Path(d) / "absent.db"), \ mock.patch.object(launchers, "HEROIC_DIR", Path(d) / "nope"): self.assertEqual(launchers.scan(), []) class HeroicTests(unittest.TestCase): def test_epic_and_gog(self): with tempfile.TemporaryDirectory() as d: base = Path(d) / "heroic" (base / "legendaryConfig" / "legendary").mkdir(parents=True) (base / "gog_store").mkdir(parents=True) (base / "legendaryConfig" / "legendary" / "installed.json").write_text( json.dumps({"abc123": {"title": "Control"}})) (base / "gog_store" / "installed.json").write_text( json.dumps({"installed": [{"appName": "777", "title": "The Witcher 3"}]})) with mock.patch.object(launchers, "LUTRIS_DB", Path(d) / "nope.db"), \ mock.patch.object(launchers, "HEROIC_DIR", base): names = {g.name for g in launchers.scan()} self.assertEqual(names, {"Control", "The Witcher 3"}) def test_gog_title_falls_back_to_install_path(self): with tempfile.TemporaryDirectory() as d: base = Path(d) / "heroic" (base / "gog_store").mkdir(parents=True) (base / "gog_store" / "installed.json").write_text( json.dumps({"installed": [{"appName": "9", "install_path": "/games/Stardew Valley"}]})) with mock.patch.object(launchers, "LUTRIS_DB", Path(d) / "nope.db"), \ mock.patch.object(launchers, "HEROIC_DIR", base): names = {g.name for g in launchers.scan()} self.assertEqual(names, {"Stardew Valley"}) if __name__ == "__main__": unittest.main()