- Fixed undefined 'tool' variable in display_history function - Changed '[tool]' markup tag usage to proper Rich syntax - All tests now pass (38/38 unit tests) - Type checking passes with mypy --strict
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
"""Unit tests for config module."""
|
|
|
|
import os
|
|
|
|
from codesnap.utils.config import Config, apply_env_overrides, load_config
|
|
|
|
|
|
class TestConfig:
|
|
"""Tests for Config class."""
|
|
|
|
def test_default_values(self) -> None:
|
|
config = Config()
|
|
assert config.max_files == 1000
|
|
assert config.max_tokens == 8000
|
|
assert config.default_format == "markdown"
|
|
|
|
def test_custom_values(self) -> None:
|
|
config = Config(max_files=500, max_tokens=4000, default_format="json")
|
|
assert config.max_files == 500
|
|
assert config.max_tokens == 4000
|
|
assert config.default_format == "json"
|
|
|
|
def test_default_ignore_patterns(self) -> None:
|
|
config = Config()
|
|
assert isinstance(config.ignore_patterns, list)
|
|
|
|
def test_default_languages(self) -> None:
|
|
config = Config()
|
|
assert isinstance(config.included_languages, list)
|
|
assert isinstance(config.excluded_languages, list)
|
|
|
|
|
|
class TestLoadConfig:
|
|
"""Tests for load_config function."""
|
|
|
|
def test_load_default_config(self) -> None:
|
|
config = load_config()
|
|
assert config.max_files == 1000
|
|
assert config.max_tokens == 8000
|
|
|
|
def test_load_nonexistent_file(self) -> None:
|
|
from pathlib import Path
|
|
config = load_config(Path("/nonexistent/path.tomll"))
|
|
assert config.max_files == 1000
|
|
|
|
|
|
class TestApplyEnvOverrides:
|
|
"""Tests for apply_env_overrides function."""
|
|
|
|
def test_no_overrides(self) -> None:
|
|
config = Config()
|
|
result = apply_env_overrides(config)
|
|
assert result.max_files == 1000
|
|
|
|
def test_max_files_override(self) -> None:
|
|
os.environ["CODSNAP_MAX_FILES"] = "500"
|
|
try:
|
|
config = Config()
|
|
result = apply_env_overrides(config)
|
|
assert result.max_files == 500
|
|
finally:
|
|
del os.environ["CODSNAP_MAX_FILES"]
|
|
|
|
def test_max_tokens_override(self) -> None:
|
|
os.environ["CODSNAP_MAX_TOKENS"] = "4000"
|
|
try:
|
|
config = Config()
|
|
result = apply_env_overrides(config)
|
|
assert result.max_tokens == 4000
|
|
finally:
|
|
del os.environ["CODSNAP_MAX_TOKENS"]
|