83 lines
2 KiB
Python
83 lines
2 KiB
Python
"""Pytest fixtures for auto-commit-service tests."""
|
|
|
|
import asyncio
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Generator
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_git_repo(tmp_path: Path) -> Generator[Path, None, None]:
|
|
"""Create a temporary git repository for testing."""
|
|
repo_path = tmp_path / "test-repo"
|
|
repo_path.mkdir()
|
|
|
|
# Initialize git repo
|
|
subprocess.run(["git", "init"], cwd=repo_path, check=True, capture_output=True)
|
|
subprocess.run(
|
|
["git", "config", "user.email", "test@test.com"],
|
|
cwd=repo_path,
|
|
check=True,
|
|
capture_output=True,
|
|
)
|
|
subprocess.run(
|
|
["git", "config", "user.name", "Test User"],
|
|
cwd=repo_path,
|
|
check=True,
|
|
capture_output=True,
|
|
)
|
|
|
|
# Create initial commit
|
|
(repo_path / "README.md").write_text("# Test Repo\n")
|
|
subprocess.run(["git", "add", "."], cwd=repo_path, check=True, capture_output=True)
|
|
subprocess.run(
|
|
["git", "commit", "-m", "Initial commit"],
|
|
cwd=repo_path,
|
|
check=True,
|
|
capture_output=True,
|
|
)
|
|
|
|
yield repo_path
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_diff() -> str:
|
|
"""Sample git diff for testing."""
|
|
return """diff --git a/src/app.py b/src/app.py
|
|
index 1234567..abcdefg 100644
|
|
--- a/src/app.py
|
|
+++ b/src/app.py
|
|
@@ -10,6 +10,10 @@ def main():
|
|
print("Hello")
|
|
+ # Add new feature
|
|
+ process_data()
|
|
+ save_results()
|
|
+ print("Done")
|
|
return 0
|
|
|
|
diff --git a/src/utils.py b/src/utils.py
|
|
new file mode 100644
|
|
index 0000000..1234567
|
|
--- /dev/null
|
|
+++ b/src/utils.py
|
|
@@ -0,0 +1,5 @@
|
|
+def helper():
|
|
+ '''Helper function'''
|
|
+ pass
|
|
"""
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_settings():
|
|
"""Create test settings."""
|
|
from auto_commit_service.config import AutoCommitSettings
|
|
|
|
return AutoCommitSettings(
|
|
service_name="test-auto-commit",
|
|
llama_service_url="http://localhost:8000",
|
|
cycle_interval_seconds=1, # Fast for tests
|
|
claude_fallback_enabled=False,
|
|
enabled=False, # Don't auto-start
|
|
)
|