"""Tests for config save/load (flat TOML writer).""" import tempfile import unittest from pathlib import Path from unittest import mock from rigdoctor import config class ConfigTests(unittest.TestCase): def test_save_load_round_trip(self): with tempfile.TemporaryDirectory() as d: cf = Path(d) / "config.toml" with mock.patch.object(config, "CONFIG_FILE", cf), mock.patch.object(config, "CONFIG_DIR", Path(d)): config.save_config({"alerts_enabled": False, "gpu_temp_alert": 88.0, "update_check_minutes": 5}) loaded = config.load_config() self.assertIs(loaded["alerts_enabled"], False) self.assertEqual(loaded["gpu_temp_alert"], 88.0) self.assertEqual(loaded["update_check_minutes"], 5) def test_list_value_round_trip(self): with tempfile.TemporaryDirectory() as d: cf = Path(d) / "config.toml" with mock.patch.object(config, "CONFIG_FILE", cf), mock.patch.object(config, "CONFIG_DIR", Path(d)): paths = ["/home/u/.local/share/Steam", "/mnt/games/SteamLibrary"] config.update_config(steam_libraries=paths) self.assertEqual(config.load_config()["steam_libraries"], paths) config.update_config(steam_libraries=[]) self.assertEqual(config.load_config()["steam_libraries"], []) def test_update_config_merges_and_keeps_defaults(self): with tempfile.TemporaryDirectory() as d: cf = Path(d) / "config.toml" with mock.patch.object(config, "CONFIG_FILE", cf), mock.patch.object(config, "CONFIG_DIR", Path(d)): config.update_config(cpu_temp_alert=70.0) self.assertEqual(config.load_config()["cpu_temp_alert"], 70.0) self.assertEqual(config.load_config()["gpu_temp_alert"], 90.0) # default preserved if __name__ == "__main__": unittest.main()