fix: Add Gitea Actions CI workflow and fix linting issues
Some checks failed
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
2026-02-04 16:59:34 +00:00
parent 571b65bcaa
commit 14739db898

178
tests/test_templates.py Normal file
View File

@@ -0,0 +1,178 @@
"""Tests for template module."""
from src.templates import (
TemplateManager,
format_message,
)
class TestTemplateManager:
"""Tests for TemplateManager class."""
def test_simple_template(self):
"""Test rendering simple template."""
manager = TemplateManager("{type}: {description}")
result = manager.render(
type="feat",
scope="",
description="add new feature"
)
assert result == "feat: add new feature"
def test_template_with_scope(self):
"""Test rendering template with scope - scope is raw since template includes parentheses."""
manager = TemplateManager("{type}({scope}): {description}")
result = manager.render(
type="feat",
scope="cli",
description="add new command"
)
assert result == "feat(cli): add new command"
def test_template_with_files(self):
"""Test rendering template with file list."""
manager = TemplateManager("{type}: {description}\n\n{files}")
result = manager.render(
type="fix",
scope="",
description="fix bug",
files=["src/main.py", "tests/test_main.py"]
)
assert "fix: fix bug" in result
assert "src/main.py" in result
assert "tests/test_main.py" in result
def test_template_with_body(self):
"""Test rendering template with body."""
manager = TemplateManager("{type}: {description}\n\n{body}")
result = manager.render(
type="docs",
scope="",
description="update readme",
body="Added new sections to documentation"
)
assert "docs: update readme" in result
assert "Added new sections" in result
def test_empty_scope_handling(self):
"""Test that empty scope is handled correctly."""
manager = TemplateManager("{type}{scope}: {description}")
result = manager.render(
type="chore",
scope="",
description="update dependencies"
)
assert result == "chore: update dependencies"
def test_max_files_display(self):
"""Test that more than 10 files shows count."""
files = [f"file{i}.py" for i in range(15)]
manager = TemplateManager("{files}")
result = manager.render(
type="feat",
scope="",
description="add files",
files=files
)
assert "... and 5 more" in result
def test_default_template(self):
"""Test using default template - scope is empty in this case."""
manager = TemplateManager()
result = manager.render(
type="feat",
scope="",
description="test"
)
assert result == "feat: test"
def test_extra_kwargs(self):
"""Test passing extra kwargs."""
manager = TemplateManager("{type}: {custom}")
result = manager.render(
type="test",
scope="",
description="",
custom="custom value"
)
assert result == "test: custom value"
class TestTemplateValidation:
"""Tests for template validation."""
def test_valid_template(self):
"""Test validating a valid template."""
is_valid, error = TemplateManager.validate_template(
"{type}: {description}"
)
assert is_valid is True
assert error is None
def test_invalid_placeholder(self):
"""Test detecting invalid placeholders."""
is_valid, error = TemplateManager.validate_template(
"{type}: {invalid}"
)
assert is_valid is False
assert error is not None
assert "invalid" in error
def test_multiple_invalid_placeholders(self):
"""Test detecting multiple invalid placeholders."""
is_valid, error = TemplateManager.validate_template(
"{foo} {bar} {baz}"
)
assert is_valid is False
class TestFormatMessage:
"""Tests for format_message function."""
def test_format_message_simple(self):
"""Test formatting a simple message - scope is empty by default."""
result = format_message(
type="feat",
scope="",
description="add new command"
)
assert result == "feat: add new command"
def test_format_message_with_scope(self):
"""Test formatting with scope."""
result = format_message(
type="fix",
scope="auth",
description="fix login issue",
template="[{type}] ({scope}) - {description}"
)
assert result == "[fix] (auth) - fix login issue"
def test_format_message_with_files(self):
"""Test formatting with file list."""
result = format_message(
type="docs",
scope="",
description="update readme",
template="{type}: {description}\n\n{files}",
files=["README.md", "CONTRIBUTING.md"]
)
assert "docs:" in result
assert "README.md" in result
class TestDefaultTemplates:
"""Tests for default templates."""
def test_default_templates_exist(self):
"""Test that default templates are available."""
templates = TemplateManager.get_default_templates()
assert "simple" in templates
assert "detailed" in templates
assert "conventional" in templates
def test_simple_template_is_default(self):
"""Test that simple is the default template."""
templates = TemplateManager.get_default_templates()
assert templates["simple"] == "{type}{scope}: {description}"