"""Tests for Local Code Assistant configuration.""" import pytest from pathlib import Path from unittest.mock import Mock, patch from local_code_assistant.services.config import ConfigService class TestConfigService: """Tests for the configuration service.""" def test_default_ollama_base_url(self): """Test default Ollama base URL.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.ollama_base_url == "http://localhost:11434" def test_default_ollama_model(self): """Test default Ollama model.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.ollama_model == "codellama" def test_default_ollama_timeout(self): """Test default Ollama timeout.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.ollama_timeout == 8000 def test_env_override_ollama_url(self): """Test environment variable override for Ollama URL.""" env = {'OLLAMA_BASE_URL': 'http://custom:9000'} with patch.dict('os.environ', env, clear=False): config = ConfigService("/nonexistent") assert config.ollama_base_url == 'http://custom:9000' def test_env_override_ollama_model(self): """Test environment variable override for model.""" env = {'OLLAMA_MODEL': 'custom-model'} with patch.dict('os.environ', env, clear=False): config = ConfigService("/nonexistent") assert config.ollama_model == 'custom-model' def test_env_override_timeout(self): """Test environment variable override for timeout.""" env = {'OLLAMA_TIMEOUT': '120'} with patch.dict('os.environ', env, clear=False): config = ConfigService("/nonexistent") assert config.ollama_timeout == 120 def test_streaming_default(self): """Test default streaming setting.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.streaming is True def test_default_language(self): """Test default programming language.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.default_language == "python" def test_temperature_default(self): """Test default temperature.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.temperature == 0.2 def test_max_tokens_default(self): """Test default max tokens.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.max_tokens == 4000 def test_syntax_highlighting_default(self): """Test default syntax highlighting.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.syntax_highlighting is True def test_clipboard_enabled_default(self): """Test default clipboard setting.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") assert config.clipboard_enabled is True def test_set_ollama_base_url(self): """Test setting Ollama base URL.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") config.ollama_base_url = "http://new:9000" assert config.ollama_base_url == "http://new:9000" def test_set_ollama_model(self): """Test setting Ollama model.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") config.ollama_model = "new-model" assert config.ollama_model == "new-model" def test_get_nested_config(self): """Test getting nested configuration values.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") value = config.get("ollama.base_url") assert value == "http://localhost:11434" def test_get_missing_config(self): """Test getting missing configuration with default.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") value = config.get("nonexistent.key", "default") assert value == "default" def test_set_nested_config(self): """Test setting nested configuration values.""" with patch('os.getenv', return_value=None): config = ConfigService("/nonexistent") config.set("new.setting", "value") value = config.get("new.setting") assert value == "value"