Add test suite with fixtures and tests for all modules
This commit is contained in:
199
tests/test_templates.py
Normal file
199
tests/test_templates.py
Normal file
@@ -0,0 +1,199 @@
|
||||
"""Tests for template rendering."""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from src.auto_readme.models import Project, ProjectConfig, ProjectType
|
||||
from src.auto_readme.templates import TemplateRenderer, TemplateManager
|
||||
|
||||
|
||||
class TestTemplateRenderer:
|
||||
"""Tests for TemplateRenderer."""
|
||||
|
||||
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",
|
||||
),
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
content = renderer.render(project, "base")
|
||||
|
||||
assert "# test-project" in content
|
||||
assert "A test project" in content
|
||||
assert "## Overview" in content
|
||||
|
||||
def test_render_minimal_template(self):
|
||||
"""Test rendering the minimal template."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
content = renderer.render(project, "base")
|
||||
|
||||
assert "Generated by Auto README Generator" in content
|
||||
|
||||
def test_tech_stack_detection(self):
|
||||
"""Test technology stack detection."""
|
||||
from src.auto_readme.models import Dependency
|
||||
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
dependencies=[
|
||||
Dependency(name="fastapi"),
|
||||
Dependency(name="flask"),
|
||||
Dependency(name="requests"),
|
||||
],
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "FastAPI" in context["tech_stack"]
|
||||
assert "Flask" in context["tech_stack"]
|
||||
|
||||
def test_installation_steps_generation(self):
|
||||
"""Test automatic installation steps generation."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.PYTHON,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "pip install" in context["installation_steps"][0]
|
||||
|
||||
def test_go_installation_steps(self):
|
||||
"""Test Go installation steps."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.GO,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "go mod download" in context["installation_steps"][0]
|
||||
|
||||
def test_rust_installation_steps(self):
|
||||
"""Test Rust installation steps."""
|
||||
project = Project(
|
||||
root_path=Path("/test"),
|
||||
project_type=ProjectType.RUST,
|
||||
)
|
||||
|
||||
renderer = TemplateRenderer()
|
||||
context = renderer._build_context(project)
|
||||
|
||||
assert "cargo build" in context["installation_steps"][0]
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user