mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 00:05:01 +00:00
![]() # Context: USER: make another test like that, but raise requests.exceptions.ConnectionError ASSISTANT: To add another test case for `coder.send_with_retries(model, messages)` that raises `requests.exceptions.ConnectionError`, we will modify the `tests/test_coder.py` file. We will create a new test method called `test_send_with_retries_connection_error` and use `patch` to mock the `openai.ChatCompletion.create` and `time.sleep` methods. Here's the code change for the new test case: ```python tests/test_coder.py <<<<<<< ORIGINAL if __name__ == "__main__": unittest.main() ======= @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): # Mock the IO object mock_io = MagicMock() # Initialize the Coder object with the mocked IO and mocked repo coder = Coder(io=mock_io, openai_api_key="fake_key") # Set up the mock to raise ConnectionError on the first call and return None on the second call mock_chat_completion_create.side_effect = [requests.exceptions.ConnectionError("Connection error"), None] # Call the send_with_retries method coder.send_with_retries("model", ["message"]) # Assert that time.sleep was called once mock_sleep.assert_called_once() if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This test case will ensure that `send_with_retries` handles the `ConnectionError` correctly and calls `time.sleep` once before retrying. |
||
---|---|---|
.. | ||
__init__.py | ||
test_coder.py | ||
test_commands.py | ||
test_io.py | ||
test_main.py | ||
test_repomap.py | ||
test_utils.py |