style: Format code with linter and improve import sorting

This commit is contained in:
Paul Gauthier (aider) 2025-03-07 16:48:33 -08:00
parent 2ffe49130d
commit 5f694f228f

View file

@ -4,7 +4,11 @@ from unittest.mock import MagicMock, patch
from aider.coders.base_coder import Coder from aider.coders.base_coder import Coder
from aider.io import InputOutput from aider.io import InputOutput
from aider.models import Model from aider.models import Model
from aider.reasoning_tags import REASONING_TAG, format_reasoning_content, replace_reasoning_tags from aider.reasoning_tags import (
REASONING_TAG,
format_reasoning_content,
replace_reasoning_tags,
)
class TestReasoning(unittest.TestCase): class TestReasoning(unittest.TestCase):
@ -13,46 +17,47 @@ class TestReasoning(unittest.TestCase):
# Setup IO with no streaming, no pretty # Setup IO with no streaming, no pretty
io = InputOutput(pretty=False, stream=False) io = InputOutput(pretty=False, stream=False)
io.ai_output = MagicMock() io.ai_output = MagicMock()
# Setup model and coder # Setup model and coder
model = Model("gpt-3.5-turbo") model = Model("gpt-3.5-turbo")
coder = Coder.create(model, None, io=io) coder = Coder.create(model, None, io=io)
# Test data # Test data
reasoning_content = "My step-by-step reasoning process" reasoning_content = "My step-by-step reasoning process"
main_content = "Final answer after reasoning" main_content = "Final answer after reasoning"
# Mock completion response with reasoning content # Mock completion response with reasoning content
class MockCompletion: class MockCompletion:
def __init__(self, content, reasoning_content): def __init__(self, content, reasoning_content):
self.content = content self.content = content
self.reasoning_content = reasoning_content self.reasoning_content = reasoning_content
mock_completion = MockCompletion(main_content, reasoning_content) mock_completion = MockCompletion(main_content, reasoning_content)
# Mock the model's send_completion method # Mock the model's send_completion method
with patch.object(model, 'send_completion', return_value=mock_completion): with patch.object(model, "send_completion", return_value=mock_completion):
# Call send with a simple message # Call send with a simple message
messages = [{"role": "user", "content": "test prompt"}] messages = [{"role": "user", "content": "test prompt"}]
coder.send(messages) coder.send(messages)
# Check if ai_output was called with formatted content # Check if ai_output was called with formatted content
io.ai_output.assert_called_once() io.ai_output.assert_called_once()
output = io.ai_output.call_args[0][0] output = io.ai_output.call_args[0][0]
# Output should contain formatted reasoning tags # Output should contain formatted reasoning tags
self.assertIn("Thinking ...", output) self.assertIn("Thinking ...", output)
self.assertIn("... done thinking", output) self.assertIn("... done thinking", output)
# Output should include both reasoning and main content # Output should include both reasoning and main content
self.assertIn(reasoning_content, output) self.assertIn(reasoning_content, output)
self.assertIn(main_content, output) self.assertIn(main_content, output)
# Ensure proper order: reasoning first, then main content # Ensure proper order: reasoning first, then main content
reasoning_pos = output.find(reasoning_content) reasoning_pos = output.find(reasoning_content)
main_pos = output.find(main_content) main_pos = output.find(main_content)
self.assertLess(reasoning_pos, main_pos, self.assertLess(
"Reasoning content should appear before main content") reasoning_pos, main_pos, "Reasoning content should appear before main content"
)
if __name__ == "__main__": if __name__ == "__main__":