You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
|
1 month ago
|
import logging
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from ramscreen.config import Config, load_config
|
||
|
|
|
||
|
|
|
||
|
|
def test_fehlende_datei_liefert_standardwerte(tmp_path: Path):
|
||
|
|
cfg = load_config(tmp_path / "gibt-es-nicht.toml")
|
||
|
|
assert cfg == Config()
|
||
|
|
assert cfg.port == "/dev/turing-screen"
|
||
|
|
assert cfg.brightness == 20
|
||
|
|
assert cfg.rotate_180 is False
|
||
|
|
assert cfg.warn_free_percent == 20
|
||
|
|
assert cfg.crit_free_percent == 10
|
||
|
|
assert cfg.top_n == 5
|
||
|
|
assert cfg.memory_interval == 2
|
||
|
|
assert cfg.apps_interval == 10
|
||
|
|
|
||
|
|
|
||
|
|
def test_einzelne_schluessel_ueberschreiben(tmp_path: Path):
|
||
|
|
path = tmp_path / "config.toml"
|
||
|
|
path.write_text('brightness = 35\nrotate_180 = true\nport = "/dev/ttyACM1"\n', encoding="utf-8")
|
||
|
|
cfg = load_config(path)
|
||
|
|
assert cfg.brightness == 35
|
||
|
|
assert cfg.rotate_180 is True
|
||
|
|
assert cfg.port == "/dev/ttyACM1"
|
||
|
|
assert cfg.top_n == 5 # nicht gesetzt → Standard
|
||
|
|
|
||
|
|
|
||
|
|
def test_unbekannter_schluessel_wird_ignoriert_und_gewarnt(tmp_path: Path, caplog):
|
||
|
|
path = tmp_path / "config.toml"
|
||
|
|
path.write_text("helligkeit = 50\n", encoding="utf-8")
|
||
|
|
with caplog.at_level(logging.WARNING):
|
||
|
|
cfg = load_config(path)
|
||
|
|
assert cfg == Config()
|
||
|
|
assert "helligkeit" in caplog.text
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("text", ["brightness = 101\n", "brightness = -1\n", "top_n = 0\n", "top_n = 6\n"])
|
||
|
|
def test_ungueltige_werte_werden_abgelehnt(tmp_path: Path, text: str):
|
||
|
|
path = tmp_path / "config.toml"
|
||
|
|
path.write_text(text, encoding="utf-8")
|
||
|
|
with pytest.raises(ValueError):
|
||
|
|
load_config(path)
|