"""Tests for configuration module.""" import pytest from pydantic import ValidationError from src.config import Settings class TestSettings: """Test Settings validation.""" def test_default_settings(self): """Test default settings are valid.""" settings = Settings() assert settings.inference_port == 3161 assert settings.inference_backend == "ollama" assert settings.default_max_tokens == 512 def test_invalid_port_low(self): """Test invalid port below range.""" with pytest.raises(ValidationError): Settings(inference_port=0) def test_invalid_port_high(self): """Test invalid port above range.""" with pytest.raises(ValidationError): Settings(inference_port=70000) def test_invalid_backend(self): """Test invalid backend type.""" with pytest.raises(ValidationError): Settings(inference_backend="invalid") def test_valid_backends(self): """Test valid backend types.""" ollama = Settings(inference_backend="ollama") assert ollama.inference_backend == "ollama" vllm = Settings(inference_backend="vllm") assert vllm.inference_backend == "vllm" def test_invalid_ollama_host(self): """Test invalid Ollama host URL.""" with pytest.raises(ValidationError): Settings(ollama_host="invalid-url") def test_valid_ollama_host(self): """Test valid Ollama host URLs.""" http = Settings(ollama_host="http://localhost:11434") assert http.ollama_host == "http://localhost:11434" https = Settings(ollama_host="https://ollama.example.com") assert https.ollama_host == "https://ollama.example.com" def test_ollama_host_trailing_slash_removed(self): """Test trailing slash is removed from Ollama host.""" settings = Settings(ollama_host="http://localhost:11434/") assert settings.ollama_host == "http://localhost:11434" def test_max_tokens_limit_validation(self): """Test max_tokens_limit validation.""" with pytest.raises(ValidationError): Settings(max_tokens_limit=0) valid = Settings(max_tokens_limit=8192) assert valid.max_tokens_limit == 8192 def test_temperature_validation(self): """Test temperature validation.""" with pytest.raises(ValidationError): Settings(default_temperature=-0.1) with pytest.raises(ValidationError): Settings(default_temperature=2.1) valid = Settings(default_temperature=1.5) assert valid.default_temperature == 1.5 def test_top_p_validation(self): """Test top_p validation.""" with pytest.raises(ValidationError): Settings(default_top_p=-0.1) with pytest.raises(ValidationError): Settings(default_top_p=1.1) valid = Settings(default_top_p=0.95) assert valid.default_top_p == 0.95