Skip to content

Commit

Permalink
refactor: Consolidate subprocess.call mock in test_pipe_editor
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-gauthier committed Nov 23, 2024
1 parent 14522db commit e63df83
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/basic/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,29 @@ def test_pipe_editor():
patch("aider.editor.write_temp_file") as mock_write,
patch("builtins.open") as mock_open,
patch("os.remove") as mock_remove,
patch("subprocess.call") as mock_subprocess,
):
# Setup mocks
mock_write.return_value = "temp.txt"
mock_file = MagicMock()
mock_file.__enter__.return_value.read.return_value = modified_content
mock_open.return_value = mock_file

with patch("subprocess.call") as mock_subprocess:
# Test with default editor
result = pipe_editor(test_content)
assert result == modified_content
mock_write.assert_called_with(test_content, None)
mock_subprocess.assert_called()

# Test with custom editor
result = pipe_editor(test_content, editor="code")
assert result == modified_content
mock_subprocess.assert_called()

# Test with suffix
result = pipe_editor(test_content, suffix="md")
assert result == modified_content
mock_write.assert_called_with(test_content, "md")
# Test with default editor
result = pipe_editor(test_content)
assert result == modified_content
mock_write.assert_called_with(test_content, None)
mock_subprocess.assert_called()

# Test with custom editor
result = pipe_editor(test_content, editor="code")
assert result == modified_content
mock_subprocess.assert_called()

# Test with suffix
result = pipe_editor(test_content, suffix="md")
assert result == modified_content
mock_write.assert_called_with(test_content, "md")

# Test cleanup on permission error
mock_remove.side_effect = PermissionError
Expand Down

0 comments on commit e63df83

Please sign in to comment.