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,197 +1,145 @@
|
||||
"""Tests for template rendering."""
|
||||
"""Tests for template engine."""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.auto_readme.models import Project, ProjectConfig, ProjectType
|
||||
from src.auto_readme.templates import TemplateRenderer, TemplateManager
|
||||
from project_scaffold_cli.template_engine import TemplateEngine
|
||||
|
||||
|
||||
class TestTemplateRenderer:
|
||||
"""Tests for TemplateRenderer."""
|
||||
class TestTemplateEngine:
|
||||
"""Test TemplateEngine class."""
|
||||
|
||||
def test_render_base_template(self):
|
||||
"""Test rendering the base template."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
config=ProjectConfig(
|
||||
name="test-project",
|
||||
description="A test project",
|
||||
),
|
||||
)
|
||||
def test_engine_initialization(self):
|
||||
"""Test engine can be initialized."""
|
||||
engine = TemplateEngine()
|
||||
assert engine is not None
|
||||
assert engine.SUPPORTED_LANGUAGES == ["python", "nodejs", "go", "rust"]
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
content = renderer.render(project, "base")
|
||||
def test_render_language_template_python(self):
|
||||
"""Test rendering Python template."""
|
||||
engine = TemplateEngine()
|
||||
context = {
|
||||
"project_name": "test-project",
|
||||
"project_slug": "test-project",
|
||||
"author": "Test Author",
|
||||
"email": "test@example.com",
|
||||
"description": "A test project",
|
||||
"license": "MIT",
|
||||
"year": "2024",
|
||||
"language": "python",
|
||||
}
|
||||
|
||||
assert "# test-project" in content
|
||||
assert "A test project" in content
|
||||
assert "## Overview" in content
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_dir = Path(tmpdir) / "test-project"
|
||||
output_dir.mkdir()
|
||||
engine.render_language_template("python", context, output_dir)
|
||||
|
||||
def test_render_minimal_template(self):
|
||||
"""Test rendering the minimal template."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
)
|
||||
assert (output_dir / "setup.py").exists()
|
||||
assert (output_dir / "README.md").exists()
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
content = renderer.render(project, "base")
|
||||
def test_render_language_template_go(self):
|
||||
"""Test rendering Go template."""
|
||||
engine = TemplateEngine()
|
||||
context = {
|
||||
"project_name": "test-go-project",
|
||||
"project_slug": "test-go-project",
|
||||
"author": "Test Author",
|
||||
"email": "test@example.com",
|
||||
"description": "A test Go project",
|
||||
"license": "MIT",
|
||||
"year": "2024",
|
||||
"language": "go",
|
||||
}
|
||||
|
||||
assert "Generated by Auto README Generator" in content
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_dir = Path(tmpdir) / "test-go-project"
|
||||
output_dir.mkdir()
|
||||
engine.render_language_template("go", context, output_dir)
|
||||
|
||||
def test_tech_stack_detection(self):
|
||||
"""Test technology stack detection."""
|
||||
from src.auto_readme.models import Dependency
|
||||
assert (output_dir / "go.mod").exists()
|
||||
assert (output_dir / "main.go").exists()
|
||||
assert (output_dir / "README.md").exists()
|
||||
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
dependencies=[
|
||||
Dependency(name="fastapi"),
|
||||
Dependency(name="flask"),
|
||||
Dependency(name="requests"),
|
||||
],
|
||||
)
|
||||
def test_render_language_template_rust(self):
|
||||
"""Test rendering Rust template."""
|
||||
engine = TemplateEngine()
|
||||
context = {
|
||||
"project_name": "test-rust-project",
|
||||
"project_slug": "test-rust-project",
|
||||
"author": "Test Author",
|
||||
"email": "test@example.com",
|
||||
"description": "A test Rust project",
|
||||
"license": "MIT",
|
||||
"year": "2024",
|
||||
"language": "rust",
|
||||
}
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_dir = Path(tmpdir) / "test-rust-project"
|
||||
output_dir.mkdir()
|
||||
engine.render_language_template("rust", context, output_dir)
|
||||
|
||||
assert "FastAPI" in context["tech_stack"]
|
||||
assert "Flask" in context["tech_stack"]
|
||||
assert (output_dir / "Cargo.toml").exists()
|
||||
assert (output_dir / "src" / "main.rs").exists()
|
||||
assert (output_dir / "README.md").exists()
|
||||
|
||||
def test_installation_steps_generation(self):
|
||||
"""Test automatic installation steps generation."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
)
|
||||
def test_render_language_template_unsupported(self):
|
||||
"""Test rendering unsupported language."""
|
||||
engine = TemplateEngine()
|
||||
context = {"project_name": "test"}
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
engine.render_language_template(
|
||||
"unsupported", context, Path(tmpdir)
|
||||
)
|
||||
assert "Unsupported language" in str(exc_info.value)
|
||||
|
||||
assert "pip install" in context["installation_steps"][0]
|
||||
def test_render_ci_template_github(self):
|
||||
"""Test rendering GitHub Actions CI template."""
|
||||
engine = TemplateEngine()
|
||||
context = {
|
||||
"project_name": "test-project",
|
||||
"project_slug": "test-project",
|
||||
}
|
||||
|
||||
def test_go_installation_steps(self):
|
||||
"""Test Go installation steps."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.GO,
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_dir = Path(tmpdir)
|
||||
engine.render_ci_template("github", context, output_dir)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
workflow_path = (
|
||||
output_dir / ".github" / "workflows" / "ci.yml"
|
||||
)
|
||||
assert workflow_path.exists()
|
||||
content = workflow_path.read_text()
|
||||
assert "CI" in content
|
||||
|
||||
assert "go mod download" in context["installation_steps"][0]
|
||||
def test_render_ci_template_gitlab(self):
|
||||
"""Test rendering GitLab CI template."""
|
||||
engine = TemplateEngine()
|
||||
context = {
|
||||
"project_name": "test-project",
|
||||
"project_slug": "test-project",
|
||||
}
|
||||
|
||||
def test_rust_installation_steps(self):
|
||||
"""Test Rust installation steps."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.RUST,
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_dir = Path(tmpdir)
|
||||
engine.render_ci_template("gitlab", context, output_dir)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
assert (output_dir / ".gitlab-ci.yml").exists()
|
||||
|
||||
assert "cargo build" in context["installation_steps"][0]
|
||||
def test_validate_context_missing_required(self):
|
||||
"""Test context validation with missing required fields."""
|
||||
engine = TemplateEngine()
|
||||
missing = engine.validate_context({})
|
||||
assert "project_name" in missing
|
||||
assert "author" in missing
|
||||
|
||||
def test_feature_detection(self):
|
||||
"""Test automatic feature detection."""
|
||||
from src.auto_readme.models import Function, Class, SourceFile, FileType
|
||||
|
||||
functions = [
|
||||
Function(name="test_func", line_number=1),
|
||||
]
|
||||
classes = [
|
||||
Class(name="TestClass", line_number=1),
|
||||
]
|
||||
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
files=[
|
||||
SourceFile(
|
||||
path=Path("test.py"),
|
||||
file_type=FileType.SOURCE,
|
||||
functions=functions,
|
||||
classes=classes,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "Contains 1 classes" in context["features"]
|
||||
assert "Contains 1 functions" in context["features"]
|
||||
|
||||
def test_custom_context_override(self):
|
||||
"""Test custom context can override auto-detected values."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
content = renderer.render(
|
||||
project,
|
||||
"base",
|
||||
title="Custom Title",
|
||||
description="Custom description",
|
||||
)
|
||||
|
||||
assert "# Custom Title" in content
|
||||
assert "Custom description" in content
|
||||
|
||||
def test_contributing_guidelines(self):
|
||||
"""Test contributing guidelines generation."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "Fork the repository" in context["contributing_guidelines"]
|
||||
assert "git checkout -b" in context["contributing_guidelines"]
|
||||
assert "pytest" in context["contributing_guidelines"]
|
||||
|
||||
def test_javascript_contributing_guidelines(self):
|
||||
"""Test JavaScript contributing guidelines."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.JAVASCRIPT,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "npm test" in context["contributing_guidelines"]
|
||||
|
||||
|
||||
class TestTemplateManager:
|
||||
"""Tests for TemplateManager."""
|
||||
|
||||
def test_list_templates(self):
|
||||
"""Test listing available templates."""
|
||||
manager = TemplateManager()
|
||||
templates = manager.list_templates()
|
||||
|
||||
assert "base" in templates
|
||||
|
||||
def test_get_template_path_builtin(self):
|
||||
"""Test getting path for built-in template."""
|
||||
manager = TemplateManager()
|
||||
path = manager.get_template_path("base")
|
||||
|
||||
assert path is None
|
||||
|
||||
def test_get_template_path_custom(self):
|
||||
"""Test getting path for custom template."""
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
manager = TemplateManager(Path(tmp_dir))
|
||||
path = manager.get_template_path("custom.md.j2")
|
||||
assert path is not None
|
||||
def test_validate_context_complete(self):
|
||||
"""Test context validation with all required fields."""
|
||||
engine = TemplateEngine()
|
||||
context = {"project_name": "test", "author": "Test Author"}
|
||||
missing = engine.validate_context(context)
|
||||
assert len(missing) == 0
|
||||
|
||||
Reference in New Issue
Block a user