Initial upload: gitignore-generator-cli v1.0.0 with CI/CD workflow
This commit is contained in:
78
tests/conftest.py
Normal file
78
tests/conftest.py
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
"""Pytest configuration and fixtures."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from gitignore_generator import __version__
|
||||||
|
|
||||||
|
|
||||||
|
@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() as tmpdir:
|
||||||
|
from pathlib import Path
|
||||||
|
original_cache = Path.home() / ".cache" / "gitignore-generator"
|
||||||
|
|
||||||
|
class TestCacheManager(CacheManager):
|
||||||
|
def __init__(self, tmpdir):
|
||||||
|
self._cache_dir = Path(tmpdir)
|
||||||
|
|
||||||
|
yield TestCacheManager(tempfile.mkdtemp())
|
||||||
Reference in New Issue
Block a user