~reviewer/hello-hut

5306422adf89ae9f8902ba5a85f4963cc79f5557 — Jun Takahashi 2 months ago 05b11e8
tests: cover config parsing edge cases
1 files changed, 24 insertions(+), 0 deletions(-)

A tests/test_config.py
A tests/test_config.py => tests/test_config.py +24 -0
@@ 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)