From 091bcaa1a2e21ab68ee5445c48fe34962cbb5d1e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 4 Jun 2023 05:58:06 -0700 Subject: [PATCH] aider: Updated test_send_with_retries tests to use backoff library instead of time.sleep. # Context: USER: `tests/test_coder.py` `aider/coder.py` Fix the test_send_with_retries tests since we no longer use time.sleep but backoff instead ASSISTANT: To fix the test_send_with_retries tests in `tests/test_coder.py`, we need to update the tests to use the backoff library instead of time.sleep. Here's how to do it: 1. Replace the `@patch("aider.coder.time.sleep")` with `@patch("aider.coder.backoff.expo")` in both test_send_with_retries_rate_limit_error and test_send_with_retries_connection_error tests. 2. Update the test_send_with_retries_rate_limit_error and test_send_with_retries_connection_error tests to assert that backoff.expo was called once instead of time.sleep. Here are the changes: ```python tests/test_coder.py <<<<<<< ORIGINAL @patch("aider.coder.time.sleep") def test_send_with_retries_rate_limit_error(self, mock_sleep, mock_chat_completion_create): ======= @patch("aider.coder.backoff.expo") def test_send_with_retries_rate_limit_error(self, mock_backoff_expo, mock_chat_completion_create): >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL # Assert that time.sleep was called once mock_sleep.assert_called_once() ======= # Assert that backoff.expo was called once mock_backoff_expo.assert_called_once() >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL @patch("aider.coder.time.sleep") def test_send_with_retries_connection_error(self, mock_sleep, mock_chat_completion_create): ======= @patch("aider.coder.backoff.expo") def test_send_with_retries_connection_error(self, mock_backoff_expo, mock_chat_completion_create): >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL # Assert that time.sleep was called once mock_sleep.assert_called_once() ======= # Assert that backoff.expo was called once mock_backoff_expo.assert_called_once() >>>>>>> UPDATED ``` These changes should fix the test_send_with_retries tests in `tests/test_coder.py`. --- 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 eee43897e..0fe2b5e83 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.time.sleep") - def test_send_with_retries_rate_limit_error(self, mock_sleep, mock_chat_completion_create): + @patch("aider.coder.backoff.expo") + def test_send_with_retries_rate_limit_error(self, mock_backoff_expo, 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 time.sleep was called once - mock_sleep.assert_called_once() + # Assert that backoff.expo was called once + mock_backoff_expo.assert_called_once() @patch("aider.coder.openai.ChatCompletion.create") - @patch("aider.coder.time.sleep") - def test_send_with_retries_connection_error(self, mock_sleep, mock_chat_completion_create): + @patch("aider.coder.backoff.expo") + def test_send_with_retries_connection_error(self, mock_backoff_expo, 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 time.sleep was called once - mock_sleep.assert_called_once() + # Assert that backoff.expo was called once + mock_backoff_expo.assert_called_once() if __name__ == "__main__":