~reviewer/hello-hut

ref: next hello-hut/tests/test_config.py -rw-r--r-- 739 bytes
595fc0f4 — Noor Haddad docs: document --lang 22 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)