Files
gitignore-generator-cli/tests/conftest.py
7000pctAUTO 988193b783
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
fix: resolve CI/CD issues - linting errors and test fixture
2026-01-30 15:43:32 +00:00

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))