43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from ai_typewriter.config import load_config
|
|
|
|
|
|
def test_load_default_config(tmp_path):
|
|
path = tmp_path / "config.json"
|
|
path.write_text(json.dumps({"provider": "ollama"}), encoding="utf-8")
|
|
|
|
cfg = load_config(path)
|
|
|
|
assert cfg.provider == "ollama"
|
|
assert cfg.hotkey == "ctrl+alt+a"
|
|
assert cfg.math_text_format == "unicode"
|
|
assert "Réponds directement" in cfg.system_prompt
|
|
|
|
|
|
def test_timeout_zero_disables_timeout(tmp_path):
|
|
path = tmp_path / "config.json"
|
|
path.write_text(json.dumps({"provider": "ollama", "request_timeout_seconds": 0}), encoding="utf-8")
|
|
|
|
cfg = load_config(path)
|
|
|
|
assert cfg.request_timeout_seconds is None
|
|
|
|
|
|
def test_reject_invalid_math_text_format(tmp_path):
|
|
path = tmp_path / "config.json"
|
|
path.write_text(json.dumps({"provider": "ollama", "math_text_format": "bad"}), encoding="utf-8")
|
|
|
|
with pytest.raises(ValueError):
|
|
load_config(path)
|
|
|
|
|
|
def test_reject_invalid_provider(tmp_path):
|
|
path = tmp_path / "config.json"
|
|
path.write_text(json.dumps({"provider": "bad"}), encoding="utf-8")
|
|
|
|
with pytest.raises(ValueError):
|
|
load_config(path)
|