From 1b3d947c6a66a0a87f3917469ec1cd6b0788a2c8 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 17:57:42 +0000 Subject: [PATCH] Add test configuration --- app/tests/conftest.py | 84 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 app/tests/conftest.py diff --git a/app/tests/conftest.py b/app/tests/conftest.py new file mode 100644 index 0000000..545f8c5 --- /dev/null +++ b/app/tests/conftest.py @@ -0,0 +1,84 @@ +"""Test configuration and fixtures for git-commit-message-generator tests.""" +import os +import tempfile +from pathlib import Path +from unittest.mock import MagicMock + +import pytest + +os.environ["OLLAMA_HOST"] = "http://localhost:11434" +os.environ["OLLAMA_MODEL"] = "llama3" +os.environ["PROMPT_DIR"] = str(Path(__file__).parent.parent / "prompts") + + +@pytest.fixture +def mock_ollama_client(): + """Create a mock Ollama client.""" + client = MagicMock() + client.check_connection.return_value = True + client.check_model_available.return_value = True + client.generate_commit_message.return_value = "feat(core): add new feature" + client.generate_changelog.return_value = "# Changelog\n\n## Features\n- New feature" + return client + + +@pytest.fixture +def sample_diff(): + """Sample git diff for testing.""" + return ( + "diff --git a/src/main.py b/src/main.py\n" + "index 1234567..abcdefg 100644\n" + "--- a/src/main.py\n" + "+++ b/src/main.py\n" + "@@ -1,5 +1,10 @@\n" + "+def new_function():\n" + '+ """A new function."""\n' + "+ return 'hello'\n" + "+\n" + " def existing_function():\n" + ' """Existing function."""\n' + " return 'world'\n" + ) + + +@pytest.fixture +def sample_commit_history(): + """Sample commit history for testing.""" + return [ + { + "hash": "abc1234", + "full_hash": "abc1234567890", + "message": "feat(api): add user authentication", + "author": "Test User", + "author_email": "test@example.com", + "date": "2024-01-15T10:30:00", + }, + { + "hash": "def5678", + "full_hash": "def5678901234", + "message": "fix(db): resolve connection timeout", + "author": "Test User", + "author_email": "test@example.com", + "date": "2024-01-14T15:45:00", + }, + { + "hash": "ghi9012", + "full_hash": "ghi9012345678", + "message": "docs: update README", + "author": "Test User", + "author_email": "test@example.com", + "date": "2024-01-13T09:00:00", + }, + ] + + + +@pytest.fixture +def temp_git_repo(): + """Create a temporary git repository for testing.""" + with tempfile.TemporaryDirectory() as tmpdir: + os.chdir(tmpdir) + os.system("git init") + os.system("git config user.name 'Test User'") + os.system("git config user.email 'test@example.com'") + yield tmpdir