103 lines
3.1 KiB
Python
103 lines
3.1 KiB
Python
"""Tests for configuration handling."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from project_scaffold_cli.config import Config
|
|
|
|
|
|
class TestConfig:
|
|
"""Test Config class."""
|
|
|
|
def test_default_config(self):
|
|
"""Test default configuration."""
|
|
config = Config()
|
|
assert config.author is None
|
|
assert config.email is None
|
|
assert config.license is None
|
|
assert config.description is None
|
|
|
|
def test_config_from_yaml(self):
|
|
"""Test loading configuration from YAML file."""
|
|
config_content = {
|
|
"project": {
|
|
"author": "Test Author",
|
|
"email": "test@example.com",
|
|
"license": "MIT",
|
|
"description": "Test description",
|
|
},
|
|
"defaults": {
|
|
"language": "python",
|
|
"ci": "github",
|
|
},
|
|
}
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
config_file = Path(tmpdir) / "project.yaml"
|
|
with open(config_file, "w") as f:
|
|
yaml.dump(config_content, f)
|
|
|
|
config = Config.load(str(config_file))
|
|
|
|
assert config.author == "Test Author"
|
|
assert config.email == "test@example.com"
|
|
assert config.license == "MIT"
|
|
assert config.description == "Test description"
|
|
assert config.default_language == "python"
|
|
assert config.default_ci == "github"
|
|
|
|
def test_config_save(self):
|
|
"""Test saving configuration to file."""
|
|
config = Config(
|
|
author="Test Author",
|
|
email="test@example.com",
|
|
license="MIT",
|
|
default_language="go",
|
|
)
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
config_file = Path(tmpdir) / "config.yaml"
|
|
config.save(config_file)
|
|
|
|
assert config_file.exists()
|
|
|
|
with open(config_file, "r") as f:
|
|
saved_data = yaml.safe_load(f)
|
|
|
|
assert saved_data["project"]["author"] == "Test Author"
|
|
assert saved_data["defaults"]["language"] == "go"
|
|
|
|
def test_get_template_dirs(self):
|
|
"""Test getting template directories."""
|
|
config = Config()
|
|
dirs = config.get_template_dirs()
|
|
assert len(dirs) > 0
|
|
assert any("project-scaffold" in d for d in dirs)
|
|
|
|
def test_get_custom_templates_dir(self):
|
|
"""Test getting custom templates directory."""
|
|
config = Config()
|
|
custom_dir = config.get_custom_templates_dir()
|
|
assert "project-scaffold" in custom_dir
|
|
|
|
def test_get_template_vars(self):
|
|
"""Test getting template variables for language."""
|
|
config = Config(
|
|
template_vars={
|
|
"python": {"version": "3.11"},
|
|
"nodejs": {"version": "16"},
|
|
}
|
|
)
|
|
|
|
python_vars = config.get_template_vars("python")
|
|
assert python_vars.get("version") == "3.11"
|
|
|
|
nodejs_vars = config.get_template_vars("nodejs")
|
|
assert nodejs_vars.get("version") == "16"
|
|
|
|
other_vars = config.get_template_vars("go")
|
|
assert other_vars == {}
|