Initial upload: PatternForge CLI tool with pattern detection and boilerplate generation
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-02-02 22:26:07 +00:00
parent 02cdd8f38e
commit d38d23a594

98
tests/test_template.py Normal file
View File

@@ -0,0 +1,98 @@
import tempfile
from pathlib import Path
from patternforge.config import Config
from patternforge.template import TemplateManager
class TestTemplateManager:
def setup_method(self) -> None:
self.config = Config()
self.tmpdir = tempfile.TemporaryDirectory()
def teardown_method(self) -> None:
self.tmpdir.cleanup()
def test_create_template(self) -> None:
pattern_file = Path(self.tmpdir.name) / "patterns.yaml"
pattern_file.write_text(
"""
language: python
naming_conventions:
snake_case: [example, test]
style:
indent_size: 4
summary:
primary_naming: snake_case
"""
)
manager = TemplateManager(self.config)
manager.create_template("test-template", str(pattern_file), description="Test")
template_path = self.config.templates_dir / "test-template.yaml"
assert template_path.exists()
def test_list_templates(self) -> None:
manager = TemplateManager(self.config)
templates = manager.list_templates()
assert isinstance(templates, list)
def test_get_template(self) -> None:
pattern_file = Path(self.tmpdir.name) / "patterns.yaml"
pattern_file.write_text(
"""
language: python
summary:
primary_naming: snake_case
"""
)
manager = TemplateManager(self.config)
manager.create_template("get-test", str(pattern_file))
template = manager.get_template("get-test")
assert template is not None
assert template["name"] == "get-test"
def test_remove_template(self) -> None:
pattern_file = Path(self.tmpdir.name) / "patterns.yaml"
pattern_file.write_text(
"""
language: python
summary:
primary_naming: snake_case
"""
)
manager = TemplateManager(self.config)
manager.create_template("remove-test", str(pattern_file))
assert manager.remove_template("remove-test") is True
assert manager.get_template("remove-test") is None
def test_render_template(self) -> None:
pattern_file = Path(self.tmpdir.name) / "patterns.yaml"
pattern_file.write_text(
"""
language: python
summary:
primary_naming: snake_case
"""
)
manager = TemplateManager(self.config)
manager.create_template("render-test", str(pattern_file))
content = manager.render_template(
"render-test", {"class_name": "MyClass", "entity_name": "my_entity"}
)
assert "MyClass" in content
def test_export_patterns(self) -> None:
pattern_file = Path(self.tmpdir.name) / "patterns.yaml"
pattern_file.write_text("language: python\ntest: value\n")
manager = TemplateManager(self.config)
export_path = Path(self.tmpdir.name) / "export.yaml"
manager.export_patterns(str(pattern_file), str(export_path), "yaml")
assert export_path.exists()
def test_import_patterns(self) -> None:
pattern_file = Path(self.tmpdir.name) / "import_test.yaml"
pattern_file.write_text("test: imported\n")
manager = TemplateManager(self.config)
manager.import_patterns(str(pattern_file))
imported = self.config.patterns_dir / "import_test.yaml"
assert imported.exists()