Initial upload: Project Scaffold CLI with multi-language templates and CI/CD
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
116
tests/test_gitignore.py
Normal file
116
tests/test_gitignore.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""Tests for gitignore generation."""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from project_scaffold_cli.gitignore import GitignoreGenerator
|
||||
|
||||
|
||||
class TestGitignoreGenerator:
|
||||
"""Test GitignoreGenerator class."""
|
||||
|
||||
def test_generator_initialization(self):
|
||||
"""Test generator can be initialized."""
|
||||
gen = GitignoreGenerator()
|
||||
assert gen is not None
|
||||
|
||||
def test_generate_python_gitignore(self):
|
||||
"""Test generating Python .gitignore."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_path = Path(tmpdir) / ".gitignore"
|
||||
gen.generate("python", output_path)
|
||||
|
||||
assert output_path.exists()
|
||||
content = output_path.read_text()
|
||||
|
||||
assert "__pycache__" in content
|
||||
assert "*.pyc" in content
|
||||
assert "venv/" in content
|
||||
assert ".pytest_cache" in content
|
||||
|
||||
def test_generate_nodejs_gitignore(self):
|
||||
"""Test generating Node.js .gitignore."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_path = Path(tmpdir) / ".gitignore"
|
||||
gen.generate("nodejs", output_path)
|
||||
|
||||
assert output_path.exists()
|
||||
content = output_path.read_text()
|
||||
|
||||
assert "node_modules" in content
|
||||
assert "npm-debug.log" in content
|
||||
|
||||
def test_generate_go_gitignore(self):
|
||||
"""Test generating Go .gitignore."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_path = Path(tmpdir) / ".gitignore"
|
||||
gen.generate("go", output_path)
|
||||
|
||||
assert output_path.exists()
|
||||
content = output_path.read_text()
|
||||
|
||||
assert "*.exe" in content
|
||||
assert "vendor/" in content
|
||||
|
||||
def test_generate_rust_gitignore(self):
|
||||
"""Test generating Rust .gitignore."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
output_path = Path(tmpdir) / ".gitignore"
|
||||
gen.generate("rust", output_path)
|
||||
|
||||
assert output_path.exists()
|
||||
content = output_path.read_text()
|
||||
|
||||
assert "target/" in content
|
||||
assert "Cargo.lock" in content
|
||||
|
||||
def test_generate_unsupported_language(self):
|
||||
"""Test generating gitignore for unsupported language."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
gen.generate("unsupported", Path(tmpdir) / ".gitignore")
|
||||
assert "Unsupported language" in str(exc_info.value)
|
||||
|
||||
def test_append_patterns(self):
|
||||
"""Test appending patterns to existing .gitignore."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
gitignore_path = Path(tmpdir) / ".gitignore"
|
||||
gitignore_path.write_text("# Original content\n")
|
||||
|
||||
gen.append_patterns(gitignore_path, {"*.custom", "secret.txt"})
|
||||
|
||||
content = gitignore_path.read_text()
|
||||
assert "*.custom" in content
|
||||
assert "secret.txt" in content
|
||||
|
||||
def test_get_template_content(self):
|
||||
"""Test getting raw template content."""
|
||||
gen = GitignoreGenerator()
|
||||
|
||||
python_content = gen.get_template_content("python")
|
||||
assert isinstance(python_content, str)
|
||||
assert len(python_content) > 0
|
||||
|
||||
nodejs_content = gen.get_template_content("nodejs")
|
||||
assert isinstance(nodejs_content, str)
|
||||
assert len(nodejs_content) > 0
|
||||
|
||||
def test_list_available_templates(self):
|
||||
"""Test listing available templates."""
|
||||
gen = GitignoreGenerator()
|
||||
templates = gen.list_available_templates()
|
||||
assert isinstance(templates, list)
|
||||
Reference in New Issue
Block a user