diff options
| -rw-r--r-- | hyprsunset_qt/config.py | 15 | ||||
| -rw-r--r-- | tests/test_config.py | 24 |
2 files changed, 39 insertions, 0 deletions
diff --git a/hyprsunset_qt/config.py b/hyprsunset_qt/config.py index a718861..8001f29 100644 --- a/hyprsunset_qt/config.py +++ b/hyprsunset_qt/config.py @@ -99,3 +99,18 @@ def write_config(profiles: list[Profile], path: Path = CONFIG_PATH) -> None: path = Path(path) path.parent.mkdir(parents=True, exist_ok=True) path.write_text(serialize(profiles)) + + +_TIME_RE = re.compile(r"^([01]?\d|2[0-3]):([0-5]\d)$") + + +def valid_time(s: str) -> bool: + return bool(_TIME_RE.match(s)) + + +def valid_temperature(t: int) -> bool: + return 1000 <= t <= 20000 + + +def valid_gamma(g: float) -> bool: + return 0.0 <= g <= 2.0 diff --git a/tests/test_config.py b/tests/test_config.py index 1847449..3a17c8e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -66,3 +66,27 @@ def test_write_then_read(tmp_path): def test_default_path_is_hypr_conf(): assert str(CONFIG_PATH).endswith(".config/hypr/hyprsunset.conf") + + +from hyprsunset_qt.config import valid_time, valid_temperature, valid_gamma + + +def test_valid_time(): + assert valid_time("19:40") + assert valid_time("5:00") + assert not valid_time("25:00") + assert not valid_time("19:60") + assert not valid_time("abc") + + +def test_valid_temperature(): + assert valid_temperature(5500) + assert not valid_temperature(500) + assert not valid_temperature(30000) + + +def test_valid_gamma(): + assert valid_gamma(0.8) + assert valid_gamma(0.0) + assert not valid_gamma(-1.0) + assert not valid_gamma(2.5) |
