Add test files
This commit is contained in:
48
tests/test_config.py
Normal file
48
tests/test_config.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for configuration module."""
|
||||
|
||||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from shellgenius.config import Config, get_config
|
||||
|
||||
|
||||
class TestConfig:
|
||||
def test_default_config(self):
|
||||
"""Test default configuration values."""
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:
|
||||
f.write("")
|
||||
f.flush()
|
||||
|
||||
config = Config(f.name)
|
||||
|
||||
assert config.get("ollama.host") == "localhost:11434"
|
||||
assert config.get("ollama.model") == "codellama"
|
||||
assert config.get("safety.level") == "moderate"
|
||||
|
||||
os.unlink(f.name)
|
||||
|
||||
def test_get_nested_value(self):
|
||||
"""Test getting nested configuration values."""
|
||||
config = Config()
|
||||
|
||||
assert config.get("ollama.host") is not None
|
||||
assert config.get("nonexistent.key", "default") == "default"
|
||||
|
||||
def test_environment_override(self):
|
||||
"""Test environment variable overrides."""
|
||||
os.environ["OLLAMA_MODEL"] = "custom-model"
|
||||
|
||||
config = Config()
|
||||
assert config.ollama_model == "custom-model"
|
||||
|
||||
del os.environ["OLLAMA_MODEL"]
|
||||
|
||||
def test_ollama_properties(self):
|
||||
"""Test Ollama configuration properties."""
|
||||
config = Config()
|
||||
|
||||
assert "localhost" in config.ollama_host
|
||||
assert config.ollama_model in ["codellama", "llama2", "mistral"]
|
||||
assert config.safety_level in ["strict", "moderate", "permissive"]
|
||||
Reference in New Issue
Block a user