From 84421d865142fe64df7108da4344d7687d8acf1c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 4 Jun 2023 06:05:48 -0700 Subject: [PATCH] aider: Replaced patching of `aider.coder.backoff.expo` with patching of the `print` function and updated the assertions accordingly. # Context: USER: instead of patching and checking that aider.coder.backoff.expo, patch and check "print" ASSISTANT: To patch and check the `print` function instead of `aider.coder.backoff.expo`, you can modify the `test_send_with_retries_rate_limit_error` and `test_send_with_retries_connection_error` test cases in the `tests/test_coder.py` file. Here are the changes: ```python tests/test_coder.py <<<<<<< ORIGINAL @patch("aider.coder.openai.ChatCompletion.create") @patch("aider.coder.backoff.expo") def test_send_with_retries_rate_limit_error(self, mock_backoff_expo, mock_chat_completion_create): ======= @patch("aider.coder.openai.ChatCompletion.create") @patch("builtins.print") def test_send_with_retries_rate_limit_error(self, mock_print, mock_chat_completion_create): >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL # Assert that backoff.expo was called once mock_backoff_expo.assert_called_once() ======= # Assert that print was called once mock_print.assert_called_once() >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL @patch("aider.coder.openai.ChatCompletion.create") @patch("aider.coder.backoff.expo") def test_send_with_retries_connection_error(self, mock_backoff_expo, mock_chat_completion_create): ======= @patch("aider.coder.openai.ChatCompletion.create") @patch("builtins.print") def test_send_with_retries_connection_error(self, mock_print, mock_chat_completion_create): >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL # Assert that backoff.expo was called once mock_backoff_expo.assert_called_once() ======= # Assert that print was called once mock_print.assert_called_once() >>>>>>> UPDATED ``` These changes replace the patching of `aider.coder.backoff.expo` with patching of the `print` function and update the assertions accordingly. --- tests/test_coder.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index 0fe2b5e83..cfc45db20 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -121,8 +121,8 @@ class TestCoder(unittest.TestCase): self.assertEqual(result, 'a good "commit message"') @patch("aider.coder.openai.ChatCompletion.create") - @patch("aider.coder.backoff.expo") - def test_send_with_retries_rate_limit_error(self, mock_backoff_expo, mock_chat_completion_create): + @patch("builtins.print") + def test_send_with_retries_rate_limit_error(self, mock_print, mock_chat_completion_create): # Mock the IO object mock_io = MagicMock() @@ -139,12 +139,12 @@ class TestCoder(unittest.TestCase): # Call the send_with_retries method coder.send_with_retries("model", ["message"]) - # Assert that backoff.expo was called once - mock_backoff_expo.assert_called_once() + # Assert that print was called once + mock_print.assert_called_once() @patch("aider.coder.openai.ChatCompletion.create") - @patch("aider.coder.backoff.expo") - def test_send_with_retries_connection_error(self, mock_backoff_expo, mock_chat_completion_create): + @patch("builtins.print") + def test_send_with_retries_connection_error(self, mock_print, mock_chat_completion_create): # Mock the IO object mock_io = MagicMock() @@ -161,8 +161,8 @@ class TestCoder(unittest.TestCase): # Call the send_with_retries method coder.send_with_retries("model", ["message"]) - # Assert that backoff.expo was called once - mock_backoff_expo.assert_called_once() + # Assert that print was called once + mock_print.assert_called_once() if __name__ == "__main__":