84 lines
1.6 KiB
Python
84 lines
1.6 KiB
Python
"""Pytest configuration and fixtures."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
"""Create a temporary directory for tests."""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
yield Path(tmpdir)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_api_response():
|
|
"""Mock API response for testing."""
|
|
return """# Logs
|
|
*.log
|
|
logs/
|
|
|
|
# Dependencies
|
|
node_modules/
|
|
|
|
# OS
|
|
.DS_Store
|
|
"""
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_gitignore_content():
|
|
"""Sample gitignore content for testing."""
|
|
return """# Logs
|
|
*.log
|
|
logs/
|
|
|
|
# Dependencies
|
|
node_modules/
|
|
|
|
# OS
|
|
.DS_Store
|
|
|
|
# Custom
|
|
*.custom
|
|
"""
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_requests_get(mock_api_response):
|
|
"""Mock requests.get for API calls."""
|
|
mock_response = MagicMock()
|
|
mock_response.text = mock_api_response
|
|
mock_response.raise_for_status = MagicMock()
|
|
|
|
with patch('gitignore_generator.api.requests.get') as mock_get:
|
|
mock_get.return_value = mock_response
|
|
yield mock_get
|
|
|
|
|
|
@pytest.fixture
|
|
def cache_manager():
|
|
"""Create a cache manager with temporary directory."""
|
|
from gitignore_generator.cache import CacheManager
|
|
|
|
with tempfile.TemporaryDirectory():
|
|
from pathlib import Path
|
|
|
|
class TestCacheManager(CacheManager):
|
|
def __init__(self, tmpdir):
|
|
self._cache_dir = Path(tmpdir)
|
|
|
|
yield TestCacheManager(tempfile.mkdtemp())
|
|
|
|
|
|
@pytest.fixture
|
|
def detector():
|
|
"""Create detector with temp directory."""
|
|
from gitignore_generator.detector import ProjectDetector
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
yield ProjectDetector(Path(tmpdir))
|