From 87e0c5800add4747d6274840640353cd6830791c Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 03:00:24 +0000 Subject: [PATCH] Initial upload: Git Commit AI - privacy-first CLI for generating commit messages with local LLM --- git_commit_ai/tests/conftest.py | 103 ++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 git_commit_ai/tests/conftest.py diff --git a/git_commit_ai/tests/conftest.py b/git_commit_ai/tests/conftest.py new file mode 100644 index 0000000..fa0194e --- /dev/null +++ b/git_commit_ai/tests/conftest.py @@ -0,0 +1,103 @@ +"""Pytest fixtures and configuration for Git Commit AI tests.""" + +import os +from pathlib import Path +from unittest.mock import MagicMock + +import pytest + + +@pytest.fixture +def mock_git_handler(): + """Create a mock Git handler.""" + handler = MagicMock() + handler.is_repository.return_value = True + handler.is_staged.return_value = True + handler.get_staged_changes.return_value = """diff --git a/src/main.py b/src/main.py +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 +def sample_diff(): + """Provide a sample git diff for testing.""" + return """diff --git a/src/auth.py b/src/auth.py +index 1234567..abcdefg 100644 +--- a/src/auth.py ++++ b/src/auth.py +@@ -1,3 +1,4 @@ ++from datetime import datetime + def authenticate(user_id): + if user_id is None: + return False ++ return datetime.now() +"""