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
77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
"""Pytest configuration and fixtures."""
|
|
|
|
import os
|
|
import tempfile
|
|
from pathlib import Path
|
|
from typing import Generator
|
|
|
|
import pytest
|
|
|
|
from gitignore_cli.custom_patterns import CustomPatternManager
|
|
from gitignore_cli.template_loader import TemplateLoader
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir() -> Generator[Path, None, None]:
|
|
"""Create a temporary directory for tests."""
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
yield Path(tmp)
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_template_dir(temp_dir: Path) -> Path:
|
|
"""Create a temporary template directory with sample templates."""
|
|
template_dir = temp_dir / "templates"
|
|
template_dir.mkdir()
|
|
|
|
python_template = template_dir / "python.yaml"
|
|
python_template.write_text("""
|
|
name: python
|
|
category: language
|
|
description: Python development
|
|
patterns: |
|
|
__pycache__/
|
|
*.pyc
|
|
.env
|
|
""")
|
|
|
|
node_template = template_dir / "nodejs.yaml"
|
|
node_template.write_text("""
|
|
name: node
|
|
category: language
|
|
description: Node.js development
|
|
patterns: |
|
|
node_modules/
|
|
*.log
|
|
""")
|
|
|
|
vscode_template = template_dir / "vscode.yaml"
|
|
vscode_template.write_text("""
|
|
name: vscode
|
|
category: ide
|
|
description: VSCode IDE
|
|
patterns: |
|
|
.vscode/
|
|
*.vsix
|
|
""")
|
|
|
|
return template_dir
|
|
|
|
|
|
@pytest.fixture
|
|
def template_loader(temp_template_dir: Path) -> TemplateLoader:
|
|
"""Create a TemplateLoader with temporary templates."""
|
|
return TemplateLoader(template_dir=temp_template_dir)
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_patterns_file(temp_dir: Path) -> Path:
|
|
"""Create a temporary custom patterns file."""
|
|
return temp_dir / "custom_patterns.yaml"
|
|
|
|
|
|
@pytest.fixture
|
|
def custom_pattern_manager(temp_patterns_file: Path) -> CustomPatternManager:
|
|
"""Create a CustomPatternManager with temporary storage."""
|
|
return CustomPatternManager(patterns_file=temp_patterns_file)
|