fix: correct pyproject.toml for project-scaffold-cli
- Fixed package name from auto-readme-cli to project-scaffold-cli - Fixed dependencies to match project-scaffold-cli requirements - Fixed linting import sorting issues in test files
This commit is contained in:
@@ -1,132 +1,101 @@
|
||||
"""Tests for configuration loading."""
|
||||
"""Tests for configuration handling."""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from src.auto_readme.config import ConfigLoader, ConfigValidator, ReadmeConfig
|
||||
from project_scaffold_cli.config import Config
|
||||
|
||||
|
||||
class TestConfigLoader:
|
||||
"""Tests for ConfigLoader."""
|
||||
class TestConfig:
|
||||
"""Test Config class."""
|
||||
|
||||
def test_find_config_yaml(self, tmp_path):
|
||||
"""Test finding YAML configuration file."""
|
||||
(tmp_path / ".readmerc.yaml").write_text("project_name: test")
|
||||
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
|
||||
|
||||
config_path = ConfigLoader.find_config(tmp_path)
|
||||
assert config_path is not None
|
||||
assert config_path.name == ".readmerc.yaml"
|
||||
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",
|
||||
},
|
||||
}
|
||||
|
||||
def test_find_config_yml(self, tmp_path):
|
||||
"""Test finding YML configuration file."""
|
||||
(tmp_path / ".readmerc.yml").write_text("project_name: test")
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
config_file = Path(tmpdir) / "project.yaml"
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(config_content, f)
|
||||
|
||||
config_path = ConfigLoader.find_config(tmp_path)
|
||||
assert config_path is not None
|
||||
config = Config.load(str(config_file))
|
||||
|
||||
def test_find_config_toml(self, tmp_path):
|
||||
"""Test finding TOML configuration file."""
|
||||
(tmp_path / ".readmerc").write_text("project_name = 'test'")
|
||||
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"
|
||||
|
||||
config_path = ConfigLoader.find_config(tmp_path)
|
||||
assert config_path is not None
|
||||
|
||||
def test_load_yaml_config(self, tmp_path):
|
||||
"""Test loading YAML configuration file."""
|
||||
config_file = tmp_path / ".readmerc.yaml"
|
||||
config_file.write_text("""
|
||||
project_name: "My Test Project"
|
||||
description: "A test description"
|
||||
template: "minimal"
|
||||
interactive: true
|
||||
|
||||
sections:
|
||||
order:
|
||||
- title
|
||||
- description
|
||||
- overview
|
||||
|
||||
custom_fields:
|
||||
author: "Test Author"
|
||||
email: "test@example.com"
|
||||
""")
|
||||
|
||||
config = ConfigLoader.load(config_file)
|
||||
|
||||
assert config.project_name == "My Test Project"
|
||||
assert config.description == "A test description"
|
||||
assert config.template == "minimal"
|
||||
assert config.interactive is True
|
||||
assert "author" in config.custom_fields
|
||||
|
||||
def test_load_toml_config(self, tmp_path):
|
||||
"""Test loading TOML configuration file."""
|
||||
config_file = tmp_path / "pyproject.toml"
|
||||
config_file.write_text("""
|
||||
[tool.auto-readme]
|
||||
filename = "README.md"
|
||||
sections = ["title", "description", "overview"]
|
||||
""")
|
||||
|
||||
config = ConfigLoader.load(config_file)
|
||||
|
||||
assert config.output_filename == "README.md"
|
||||
|
||||
def test_load_nonexistent_file(self):
|
||||
"""Test loading nonexistent configuration file."""
|
||||
config = ConfigLoader.load(Path("/nonexistent/config.yaml"))
|
||||
assert config.project_name is None
|
||||
|
||||
def test_load_invalid_yaml(self, tmp_path):
|
||||
"""Test loading invalid YAML raises error."""
|
||||
config_file = tmp_path / ".readmerc.yaml"
|
||||
config_file.write_text("invalid: yaml: content: [")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
ConfigLoader.load(config_file)
|
||||
|
||||
|
||||
class TestConfigValidator:
|
||||
"""Tests for ConfigValidator."""
|
||||
|
||||
def test_validate_valid_config(self):
|
||||
"""Test validating a valid configuration."""
|
||||
config = ReadmeConfig(
|
||||
project_name="test",
|
||||
template="base",
|
||||
def test_config_save(self):
|
||||
"""Test saving configuration to file."""
|
||||
config = Config(
|
||||
author="Test Author",
|
||||
email="test@example.com",
|
||||
license="MIT",
|
||||
default_language="go",
|
||||
)
|
||||
|
||||
errors = ConfigValidator.validate(config)
|
||||
assert len(errors) == 0
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
config_file = Path(tmpdir) / "config.yaml"
|
||||
config.save(config_file)
|
||||
|
||||
def test_validate_invalid_template(self):
|
||||
"""Test validating invalid template name."""
|
||||
config = ReadmeConfig(
|
||||
project_name="test",
|
||||
template="nonexistent",
|
||||
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"},
|
||||
}
|
||||
)
|
||||
|
||||
errors = ConfigValidator.validate(config)
|
||||
assert len(errors) == 1
|
||||
assert "Invalid template" in errors[0]
|
||||
python_vars = config.get_template_vars("python")
|
||||
assert python_vars.get("version") == "3.11"
|
||||
|
||||
def test_validate_invalid_section(self):
|
||||
"""Test validating invalid section name."""
|
||||
config = ReadmeConfig(
|
||||
project_name="test",
|
||||
sections={"order": ["invalid_section"]},
|
||||
)
|
||||
nodejs_vars = config.get_template_vars("nodejs")
|
||||
assert nodejs_vars.get("version") == "16"
|
||||
|
||||
errors = ConfigValidator.validate(config)
|
||||
assert len(errors) == 1
|
||||
assert "Invalid section" in errors[0]
|
||||
|
||||
def test_generate_template(self):
|
||||
"""Test generating configuration template."""
|
||||
template = ConfigValidator.generate_template()
|
||||
|
||||
assert "project_name:" in template
|
||||
assert "description:" in template
|
||||
assert "template:" in template
|
||||
assert "interactive:" in template
|
||||
other_vars = config.get_template_vars("go")
|
||||
assert other_vars == {}
|
||||
|
||||
Reference in New Issue
Block a user