From e63df83091ab7b3371c02190a6fb3bd328d3e96e Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 23 Nov 2024 14:23:26 -0800 Subject: [PATCH] refactor: Consolidate subprocess.call mock in test_pipe_editor --- tests/basic/test_editor.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/basic/test_editor.py b/tests/basic/test_editor.py index 6af973bf6..c02d1d95d 100644 --- a/tests/basic/test_editor.py +++ b/tests/basic/test_editor.py @@ -99,6 +99,7 @@ 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" @@ -106,22 +107,21 @@ def test_pipe_editor(): 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 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 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 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