mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 13:54:59 +00:00
style: Reorder imports and add whitespace in test_editor.py
This commit is contained in:
parent
860a828973
commit
6075b3dc33
1 changed files with 21 additions and 17 deletions
|
@ -1,20 +1,22 @@
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import patch, MagicMock
|
|
||||||
|
|
||||||
from aider.editor import (
|
from aider.editor import (
|
||||||
get_environment_editor,
|
|
||||||
discover_editor,
|
|
||||||
write_temp_file,
|
|
||||||
print_status_message,
|
|
||||||
file_editor,
|
|
||||||
pipe_editor,
|
|
||||||
DEFAULT_EDITOR_NIX,
|
DEFAULT_EDITOR_NIX,
|
||||||
DEFAULT_EDITOR_OS_X,
|
DEFAULT_EDITOR_OS_X,
|
||||||
DEFAULT_EDITOR_WINDOWS,
|
DEFAULT_EDITOR_WINDOWS,
|
||||||
|
discover_editor,
|
||||||
|
file_editor,
|
||||||
|
get_environment_editor,
|
||||||
|
pipe_editor,
|
||||||
|
print_status_message,
|
||||||
|
write_temp_file,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_get_environment_editor():
|
def test_get_environment_editor():
|
||||||
# Test with no environment variables set
|
# Test with no environment variables set
|
||||||
with patch.dict(os.environ, {}, clear=True):
|
with patch.dict(os.environ, {}, clear=True):
|
||||||
|
@ -29,13 +31,10 @@ def test_get_environment_editor():
|
||||||
assert get_environment_editor() == "code"
|
assert get_environment_editor() == "code"
|
||||||
|
|
||||||
# Test AIDER_EDITOR overrides all
|
# Test AIDER_EDITOR overrides all
|
||||||
with patch.dict(os.environ, {
|
with patch.dict(os.environ, {"EDITOR": "vim", "VISUAL": "code", "AIDER_EDITOR": "emacs"}):
|
||||||
"EDITOR": "vim",
|
|
||||||
"VISUAL": "code",
|
|
||||||
"AIDER_EDITOR": "emacs"
|
|
||||||
}):
|
|
||||||
assert get_environment_editor() == "emacs"
|
assert get_environment_editor() == "emacs"
|
||||||
|
|
||||||
|
|
||||||
def test_discover_editor():
|
def test_discover_editor():
|
||||||
with patch("platform.system") as mock_system:
|
with patch("platform.system") as mock_system:
|
||||||
# Test Windows default
|
# Test Windows default
|
||||||
|
@ -62,6 +61,7 @@ def test_discover_editor():
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
discover_editor()
|
discover_editor()
|
||||||
|
|
||||||
|
|
||||||
def test_write_temp_file():
|
def test_write_temp_file():
|
||||||
# Test basic file creation
|
# Test basic file creation
|
||||||
content = "test content"
|
content = "test content"
|
||||||
|
@ -81,6 +81,7 @@ def test_write_temp_file():
|
||||||
assert os.path.basename(filepath).startswith("test_")
|
assert os.path.basename(filepath).startswith("test_")
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
|
|
||||||
|
|
||||||
def test_print_status_message(capsys):
|
def test_print_status_message(capsys):
|
||||||
# Test success message
|
# Test success message
|
||||||
print_status_message(True, "Success!")
|
print_status_message(True, "Success!")
|
||||||
|
@ -92,6 +93,7 @@ def test_print_status_message(capsys):
|
||||||
captured = capsys.readouterr()
|
captured = capsys.readouterr()
|
||||||
assert "Failed!" in captured.out
|
assert "Failed!" in captured.out
|
||||||
|
|
||||||
|
|
||||||
@patch("subprocess.call")
|
@patch("subprocess.call")
|
||||||
def test_file_editor(mock_call):
|
def test_file_editor(mock_call):
|
||||||
# Test basic editor call
|
# Test basic editor call
|
||||||
|
@ -99,16 +101,18 @@ def test_file_editor(mock_call):
|
||||||
file_editor("test.txt")
|
file_editor("test.txt")
|
||||||
mock_call.assert_called_once_with(["vim", "test.txt"])
|
mock_call.assert_called_once_with(["vim", "test.txt"])
|
||||||
|
|
||||||
|
|
||||||
def test_pipe_editor():
|
def test_pipe_editor():
|
||||||
test_content = "Initial content"
|
test_content = "Initial content"
|
||||||
modified_content = "Modified content"
|
modified_content = "Modified content"
|
||||||
|
|
||||||
# Mock the file operations and editor call
|
# Mock the file operations and editor call
|
||||||
with patch("aider.editor.write_temp_file") as mock_write, \
|
with (
|
||||||
patch("aider.editor.file_editor") as mock_editor, \
|
patch("aider.editor.write_temp_file") as mock_write,
|
||||||
patch("builtins.open") as mock_open, \
|
patch("aider.editor.file_editor") as mock_editor,
|
||||||
patch("os.remove") as mock_remove:
|
patch("builtins.open") as mock_open,
|
||||||
|
patch("os.remove") as mock_remove,
|
||||||
|
):
|
||||||
# Setup mocks
|
# Setup mocks
|
||||||
mock_write.return_value = "temp.txt"
|
mock_write.return_value = "temp.txt"
|
||||||
mock_file = MagicMock()
|
mock_file = MagicMock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue