mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 05:45:00 +00:00
style: format code and improve linter compliance in test_commands.py
This commit is contained in:
parent
202a219d82
commit
1e776863ac
1 changed files with 15 additions and 9 deletions
|
@ -3,12 +3,12 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import pyperclip
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase, mock
|
from unittest import TestCase, mock
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
import pyperclip
|
||||||
|
|
||||||
from aider.coders import Coder
|
from aider.coders import Coder
|
||||||
from aider.commands import Commands, SwitchCoder
|
from aider.commands import Commands, SwitchCoder
|
||||||
|
@ -60,9 +60,10 @@ class TestCommands(TestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
# Mock pyperclip.copy and io.tool_output
|
# Mock pyperclip.copy and io.tool_output
|
||||||
with mock.patch("pyperclip.copy") as mock_copy, \
|
with (
|
||||||
mock.patch.object(io, 'tool_output') as mock_tool_output:
|
mock.patch("pyperclip.copy") as mock_copy,
|
||||||
|
mock.patch.object(io, "tool_output") as mock_tool_output,
|
||||||
|
):
|
||||||
# Invoke the /copy command
|
# Invoke the /copy command
|
||||||
commands.cmd_copy("")
|
commands.cmd_copy("")
|
||||||
|
|
||||||
|
@ -70,7 +71,9 @@ class TestCommands(TestCase):
|
||||||
mock_copy.assert_called_once_with("Second assistant message")
|
mock_copy.assert_called_once_with("Second assistant message")
|
||||||
|
|
||||||
# Assert that tool_output was called with the expected preview
|
# Assert that tool_output was called with the expected preview
|
||||||
expected_preview = "Copied last assistant message to clipboard. Preview: Second assistant message"
|
expected_preview = (
|
||||||
|
"Copied last assistant message to clipboard. Preview: Second assistant message"
|
||||||
|
)
|
||||||
mock_tool_output.assert_any_call(expected_preview)
|
mock_tool_output.assert_any_call(expected_preview)
|
||||||
|
|
||||||
def test_cmd_copy_no_assistant_messages(self):
|
def test_cmd_copy_no_assistant_messages(self):
|
||||||
|
@ -84,7 +87,7 @@ class TestCommands(TestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
# Mock io.tool_error
|
# Mock io.tool_error
|
||||||
with mock.patch.object(io, 'tool_error') as mock_tool_error:
|
with mock.patch.object(io, "tool_error") as mock_tool_error:
|
||||||
commands.cmd_copy("")
|
commands.cmd_copy("")
|
||||||
# Assert tool_error was called indicating no assistant messages
|
# Assert tool_error was called indicating no assistant messages
|
||||||
mock_tool_error.assert_called_once_with("No assistant messages found to copy.")
|
mock_tool_error.assert_called_once_with("No assistant messages found to copy.")
|
||||||
|
@ -99,9 +102,12 @@ class TestCommands(TestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
# Mock pyperclip.copy to raise an exception
|
# Mock pyperclip.copy to raise an exception
|
||||||
with mock.patch("pyperclip.copy", side_effect=pyperclip.PyperclipException("Clipboard error")), \
|
with (
|
||||||
mock.patch.object(io, 'tool_error') as mock_tool_error:
|
mock.patch(
|
||||||
|
"pyperclip.copy", side_effect=pyperclip.PyperclipException("Clipboard error")
|
||||||
|
),
|
||||||
|
mock.patch.object(io, "tool_error") as mock_tool_error,
|
||||||
|
):
|
||||||
commands.cmd_copy("")
|
commands.cmd_copy("")
|
||||||
|
|
||||||
# Assert that tool_error was called with the clipboard error message
|
# Assert that tool_error was called with the clipboard error message
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue