"""Tests for M14 game/Proton/Steam log collection.""" import tempfile import unittest from pathlib import Path from unittest import mock from rigdoctor.core import gamelogs class TailTests(unittest.TestCase): def test_tail_returns_last_bytes(self): path = Path(tempfile.mkdtemp()) / "x.log" path.write_text("A" * 100 + "TAIL") out = gamelogs._tail(path, 4) self.assertEqual(out, "TAIL") def test_tail_short_file(self): path = Path(tempfile.mkdtemp()) / "x.log" path.write_text("short") self.assertEqual(gamelogs._tail(path, 9999), "short") def test_tail_missing(self): self.assertEqual(gamelogs._tail(Path("/nope/x.log"), 10), "") class CollectTests(unittest.TestCase): def test_collect_includes_proton_and_steam(self): tmp = Path(tempfile.mkdtemp()) proton = tmp / "steam-570.log" proton.write_text("err: vkd3d device lost") console = tmp / "console-linux.txt" console.write_text("Game removed AppID 570 ... exit") with mock.patch.object(gamelogs, "_proton_logs", return_value=[proton]), \ mock.patch.object(gamelogs, "_steam_console", return_value=console): out = gamelogs.collect() self.assertIn("Proton log", out) self.assertIn("vkd3d", out) self.assertIn("Steam log", out) self.assertIn("exit", out) def test_collect_empty_when_none(self): with mock.patch.object(gamelogs, "_proton_logs", return_value=[]), \ mock.patch.object(gamelogs, "_steam_console", return_value=None): self.assertEqual(gamelogs.collect(), "") if __name__ == "__main__": unittest.main()