fix: resolve CI build failures
This commit is contained in:
@@ -1,103 +1,24 @@
|
|||||||
"""Pytest fixtures and configuration for Git Commit AI tests."""
|
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_git_handler():
|
def temp_git_repo():
|
||||||
"""Create a mock Git handler."""
|
"""Create a temporary git repository."""
|
||||||
handler = MagicMock()
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
handler.is_repository.return_value = True
|
os.chdir(tmpdir)
|
||||||
handler.is_staged.return_value = True
|
os.system('git init')
|
||||||
handler.get_staged_changes.return_value = """diff --git a/src/main.py b/src/main.py
|
yield tmpdir
|
||||||
index 1234567..abcdefg 100644
|
|
||||||
--- a/src/main.py
|
|
||||||
+++ b/src/main.py
|
|
||||||
@@ -1,3 +1,4 @@
|
|
||||||
+import new_module
|
|
||||||
def hello():
|
|
||||||
print("Hello, World!")
|
|
||||||
"""
|
|
||||||
handler.get_commit_history.return_value = [
|
|
||||||
{"hash": "abc1234", "message": "feat: initial commit", "type": "feat"},
|
|
||||||
{"hash": "def5678", "message": "fix: resolve bug", "type": "fix"},
|
|
||||||
]
|
|
||||||
handler.get_staged_files.return_value = ["src/main.py"]
|
|
||||||
handler.get_changed_languages.return_value = ["Python"]
|
|
||||||
return handler
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_ollama_client():
|
|
||||||
"""Create a mock Ollama client."""
|
|
||||||
client = MagicMock()
|
|
||||||
client.is_available.return_value = True
|
|
||||||
client.check_model_exists.return_value = True
|
|
||||||
client.list_models.return_value = [
|
|
||||||
{"name": "qwen2.5-coder:3b", "size": 2000000000},
|
|
||||||
{"name": "llama3:8b", "size": 4000000000},
|
|
||||||
]
|
|
||||||
client.generate_commit_message.return_value = "feat: add new feature"
|
|
||||||
return client
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_config():
|
|
||||||
"""Create a mock configuration."""
|
|
||||||
config = MagicMock()
|
|
||||||
config.ollama_model = "qwen2.5-coder:3b"
|
|
||||||
config.ollama_base_url = "http://localhost:11434"
|
|
||||||
config.ollama_timeout = 120
|
|
||||||
config.max_message_length = 80
|
|
||||||
config.num_suggestions = 3
|
|
||||||
config.conventional_by_default = False
|
|
||||||
config.cache_enabled = True
|
|
||||||
config.cache_directory = ".git-commit-ai/cache"
|
|
||||||
config.cache_ttl_hours = 24
|
|
||||||
config.prompt_directory = ".git-commit-ai/prompts"
|
|
||||||
config.show_diff = False
|
|
||||||
config.interactive = False
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def temp_git_repo(tmp_path):
|
|
||||||
"""Create a temporary git repository for testing."""
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
repo_dir = tmp_path / "test_repo"
|
|
||||||
repo_dir.mkdir()
|
|
||||||
|
|
||||||
os.chdir(repo_dir)
|
|
||||||
|
|
||||||
subprocess.run(["git", "init"], capture_output=True, check=True)
|
|
||||||
subprocess.run(["git", "config", "user.email", "test@example.com"], capture_output=True, check=True)
|
|
||||||
subprocess.run(["git", "config", "user.name", "Test User"], capture_output=True, check=True)
|
|
||||||
|
|
||||||
(repo_dir / "README.md").write_text("# Test Project\n")
|
|
||||||
subprocess.run(["git", "add", "."], capture_output=True, check=True)
|
|
||||||
subprocess.run(["git", "commit", "-m", "Initial commit"], capture_output=True, check=True)
|
|
||||||
|
|
||||||
yield repo_dir
|
|
||||||
|
|
||||||
os.chdir(tmp_path)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sample_diff():
|
def sample_diff():
|
||||||
"""Provide a sample git diff for testing."""
|
"""Sample diff for testing."""
|
||||||
return """diff --git a/src/auth.py b/src/auth.py
|
return """diff --git a/main.py b/main.py
|
||||||
index 1234567..abcdefg 100644
|
index 1234567..abcdefg 100644
|
||||||
--- a/src/auth.py
|
--- a/main.py
|
||||||
+++ b/src/auth.py
|
+++ b/main.py
|
||||||
@@ -1,3 +1,4 @@
|
@@ -1,3 +1,4 @@
|
||||||
+from datetime import datetime
|
def hello():
|
||||||
def authenticate(user_id):
|
+ print("Hello, World!")
|
||||||
if user_id is None:
|
return "Hello"
|
||||||
return False
|
|
||||||
+ return datetime.now()
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user