From e751655734c9cc107d526874f88ef3127578e01c Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 11:22:13 +0000 Subject: [PATCH] fix: remove unused imports from test files --- .tests/test_config.py | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .tests/test_config.py diff --git a/.tests/test_config.py b/.tests/test_config.py new file mode 100644 index 0000000..e0a42a0 --- /dev/null +++ b/.tests/test_config.py @@ -0,0 +1,93 @@ +"""Tests for ShellGenius configuration module.""" + +import os +import tempfile +from pathlib import Path + +import yaml + +from shellgenius.config import Config, get_config + + +class TestConfig: + """Test cases for configuration.""" + + def test_default_config(self): + """Test default configuration values.""" + with tempfile.TemporaryDirectory() as tmpdir: + config_path = Path(tmpdir) / "nonexistent.yaml" + config = Config(str(config_path)) + + assert config.ollama_host == "localhost:11434" + assert config.ollama_model == "codellama" + assert config.safety_level == "moderate" + + def test_custom_config(self): + """Test loading custom configuration.""" + custom_config = { + "ollama": { + "host": "custom:9999", + "model": "mistral", + "timeout": 60, + }, + "safety": { + "level": "strict", + }, + } + + with tempfile.TemporaryDirectory() as tmpdir: + config_path = Path(tmpdir) / "config.yaml" + with open(config_path, "w") as f: + yaml.dump(custom_config, f) + + config = Config(str(config_path)) + + assert config.ollama_host == "custom:9999" + assert config.ollama_model == "mistral" + assert config.safety_level == "strict" + + def test_env_override(self): + """Test environment variable overrides.""" + os.environ["OLLAMA_HOST"] = "env-host:1234" + os.environ["OLLAMA_MODEL"] = "env-model" + + try: + config = Config() + assert config.ollama_host == "env-host:1234" + assert config.ollama_model == "env-model" + finally: + del os.environ["OLLAMA_HOST"] + del os.environ["OLLAMA_MODEL"] + + def test_get_nested_value(self): + """Test getting nested configuration values.""" + config = Config() + timeout = config.get("ollama.timeout") + assert timeout == 120 or isinstance(timeout, (int, type(None))) + + def test_get_missing_key(self): + """Test getting missing key returns default.""" + config = Config() + value = config.get("nonexistent.key", "default") + assert value == "default" + + def test_merge_configs(self): + """Test merging user config with defaults.""" + with tempfile.TemporaryDirectory() as tmpdir: + config_path = Path(tmpdir) / "config.yaml" + with open(config_path, "w") as f: + yaml.dump({"ollama": {"model": "llama2"}}, f) + + config = Config(str(config_path)) + + assert config.ollama_model == "llama2" + assert config.ollama_host == "localhost:11434" + + +class TestGetConfig: + """Test get_config convenience function.""" + + def test_get_config_singleton(self): + """Test get_config returns Config instance.""" + config = get_config() + assert isinstance(config, Config)