aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_config.py
blob: ff563252f6049054ae242d0e7ac1c19ece76c6be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# tests/test_config.py
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))

import tomllib
import unittest

import deckit.config as config


class Config(unittest.TestCase):
    def test_default_config_is_valid(self):
        with open(ROOT / "config.toml", "rb") as f:
            self.assertIsNone(config.config_error(tomllib.load(f)))

    def test_rejects_bad_values(self):
        bad = [{"display": {"name": "TAB;rm"}},
               {"display": {"refresh": 0}},
               {"ports": {"command_center": 80}},
               {"ports": {"command_center": 5900, "display": 5900}}]
        for cfg in bad:
            self.assertIsNotNone(config.config_error(cfg), cfg)

    def test_user_config_path_honours_xdg(self):
        self.assertEqual(config.user_config_path().name, "config.toml")
        self.assertEqual(config.user_config_path().parent.name, "deck-it")


if __name__ == "__main__":
    unittest.main()