48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
from src import ai_client
|
|
from src import summarize
|
|
from pathlib import Path
|
|
|
|
def test_run_subagent_summarization_gemini():
|
|
with patch("src.ai_client._provider", "gemini"), \
|
|
patch("src.ai_client._gemini_client") as mock_client, \
|
|
patch("src.ai_client._ensure_gemini_client"):
|
|
mock_resp = MagicMock()
|
|
mock_resp.text = "Smart Summary"
|
|
mock_client.models.generate_content.return_value = mock_resp
|
|
|
|
res = ai_client.run_subagent_summarization("test.py", "print('hello')", True, "Outline")
|
|
assert res == "Smart Summary"
|
|
mock_client.models.generate_content.assert_called_once()
|
|
|
|
def test_run_subagent_summarization_anthropic():
|
|
with patch("src.ai_client._provider", "anthropic"), \
|
|
patch("src.ai_client._anthropic_client") as mock_client, \
|
|
patch("src.ai_client._ensure_anthropic_client"):
|
|
mock_resp = MagicMock()
|
|
mock_block = MagicMock()
|
|
mock_block.text = "Anthropic Summary"
|
|
mock_resp.content = [mock_block]
|
|
mock_client.messages.create.return_value = mock_resp
|
|
|
|
res = ai_client.run_subagent_summarization("test.py", "print('hello')", True, "Outline")
|
|
assert res == "Anthropic Summary"
|
|
mock_client.messages.create.assert_called_once()
|
|
|
|
def test_summarise_file_integration():
|
|
with patch("src.ai_client.run_subagent_summarization") as mock_run:
|
|
mock_run.return_value = "Smart AI Summary"
|
|
|
|
# Ensure we don't hit the real cache for this test
|
|
with patch("src.summarize._summary_cache") as mock_cache:
|
|
mock_cache.get_summary.return_value = None
|
|
|
|
p = Path("test_file.py")
|
|
content = "def hello():\n pass"
|
|
summary = summarize.summarise_file(p, content)
|
|
|
|
assert "Smart AI Summary" in summary
|
|
assert "**Outline:**" in summary
|
|
assert "functions: hello" in summary
|