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 / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / type-check (push) Has been cancelled
CI / build (push) Has been cancelled
116 lines
3.9 KiB
Python
116 lines
3.9 KiB
Python
"""Tests for template loader module."""
|
|
|
|
import pytest
|
|
|
|
from gitignore_cli.template_loader import TemplateLoader, TemplateInfo
|
|
|
|
|
|
class TestTemplateInfo:
|
|
"""Tests for TemplateInfo class."""
|
|
|
|
def test_template_info_creation(self):
|
|
"""Test creating a TemplateInfo instance."""
|
|
template = TemplateInfo(
|
|
name="python",
|
|
category="language",
|
|
description="Python development",
|
|
patterns="__pycache__/\n*.pyc",
|
|
)
|
|
|
|
assert template.name == "python"
|
|
assert template.category == "language"
|
|
assert template.description == "Python development"
|
|
assert "__pycache__/" in template.patterns
|
|
|
|
def test_template_info_repr(self):
|
|
"""Test TemplateInfo string representation."""
|
|
template = TemplateInfo(
|
|
name="python",
|
|
category="language",
|
|
description="Python development",
|
|
patterns="",
|
|
)
|
|
|
|
repr_str = repr(template)
|
|
assert "python" in repr_str
|
|
assert "language" in repr_str
|
|
|
|
|
|
class TestTemplateLoader:
|
|
"""Tests for TemplateLoader class."""
|
|
|
|
def test_load_single_template(self, template_loader: TemplateLoader):
|
|
"""Test loading a single template."""
|
|
template = template_loader.load_template("python")
|
|
|
|
assert template is not None
|
|
assert template.name == "python"
|
|
assert template.category == "language"
|
|
|
|
def test_load_nonexistent_template(self, template_loader: TemplateLoader):
|
|
"""Test loading a template that doesn't exist."""
|
|
template = template_loader.load_template("nonexistent")
|
|
assert template is None
|
|
|
|
def test_load_all_templates(self, template_loader: TemplateLoader):
|
|
"""Test loading all templates."""
|
|
templates = template_loader.load_all_templates()
|
|
|
|
assert len(templates) == 3
|
|
assert "python" in templates
|
|
assert "nodejs" in templates
|
|
assert "vscode" in templates
|
|
|
|
def test_get_templates_by_category(self, template_loader: TemplateLoader):
|
|
"""Test grouping templates by category."""
|
|
by_category = template_loader.get_templates_by_category()
|
|
|
|
assert "language" in by_category
|
|
assert "ide" in by_category
|
|
|
|
assert len(by_category["language"]) == 2
|
|
assert len(by_category["ide"]) == 1
|
|
|
|
def test_list_template_names(self, template_loader: TemplateLoader):
|
|
"""Test listing template names."""
|
|
names = template_loader.list_template_names()
|
|
|
|
assert len(names) == 3
|
|
assert "python" in names
|
|
assert "nodejs" in names
|
|
assert "vscode" in names
|
|
|
|
def test_get_template_info(self, template_loader: TemplateLoader):
|
|
"""Test getting template info."""
|
|
info = template_loader.get_template_info("python")
|
|
|
|
assert info is not None
|
|
assert info.name == "python"
|
|
|
|
def test_get_similar_templates(self, template_loader: TemplateLoader):
|
|
"""Test finding similar template names."""
|
|
similar = template_loader.get_similar_templates("python")
|
|
|
|
assert "python" not in similar
|
|
assert len(similar) >= 0
|
|
|
|
def test_levenshtein_distance(self, template_loader: TemplateLoader):
|
|
"""Test Levenshtein distance calculation."""
|
|
distance = template_loader._levenshtein_distance("python", "pyton")
|
|
assert distance == 1
|
|
|
|
distance = template_loader._levenshtein_distance("python", "java")
|
|
assert distance > 1
|
|
|
|
def test_get_template_path(self, template_loader: TemplateLoader):
|
|
"""Test getting template file path."""
|
|
path = template_loader.get_template_path("python")
|
|
|
|
assert path is not None
|
|
assert path.name == "python.yaml"
|
|
|
|
def test_get_nonexistent_template_path(self, template_loader: TemplateLoader):
|
|
"""Test getting path for nonexistent template."""
|
|
path = template_loader.get_template_path("nonexistent")
|
|
assert path is None
|