From 5306422adf89ae9f8902ba5a85f4963cc79f5557 Mon Sep 17 00:00:00 2001 From: Jun Takahashi Date: Wed, 12 Aug 2026 08:20:00 +0900 Subject: [PATCH] tests: cover config parsing edge cases --- tests/test_config.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/test_config.py diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000000000000000000000000000000000000..afc9daa04b93b423c46ed0b36f55e747a413cc8b --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,24 @@ +import os +import tempfile +import unittest +from unittest import mock + +from hello_hut import config + + +class ConfigTest(unittest.TestCase): + def test_missing_file(self): + self.assertEqual(config.load_config("/nonexistent/config.toml"), {}) + + def test_no_home(self): + with mock.patch.dict(os.environ, {}, clear=True): + self.assertIsNone(config.config_path()) + + @unittest.skipIf(config.tomllib is None, "needs Python 3.11+") + def test_reads_name(self): + with tempfile.NamedTemporaryFile("w", suffix=".toml", delete=False) as f: + f.write('name = "Ada"\n') + try: + self.assertEqual(config.load_config(f.name), {"name": "Ada"}) + finally: + os.unlink(f.name)