mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 13:25:00 +00:00
added import
This commit is contained in:
parent
2d1fc9f6da
commit
5263367af0
1 changed files with 8 additions and 3 deletions
|
@ -3,6 +3,7 @@ import unittest
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import openai
|
import openai
|
||||||
|
import requests
|
||||||
|
|
||||||
from aider.coder import Coder
|
from aider.coder import Coder
|
||||||
|
|
||||||
|
@ -141,7 +142,6 @@ class TestCoder(unittest.TestCase):
|
||||||
# Assert that time.sleep was called once
|
# Assert that time.sleep was called once
|
||||||
mock_sleep.assert_called_once()
|
mock_sleep.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
@patch("aider.coder.openai.ChatCompletion.create")
|
@patch("aider.coder.openai.ChatCompletion.create")
|
||||||
@patch("aider.coder.time.sleep")
|
@patch("aider.coder.time.sleep")
|
||||||
def test_send_with_retries_connection_error(self, mock_sleep, mock_chat_completion_create):
|
def test_send_with_retries_connection_error(self, mock_sleep, mock_chat_completion_create):
|
||||||
|
@ -151,8 +151,12 @@ class TestCoder(unittest.TestCase):
|
||||||
# Initialize the Coder object with the mocked IO and mocked repo
|
# Initialize the Coder object with the mocked IO and mocked repo
|
||||||
coder = Coder(io=mock_io, openai_api_key="fake_key")
|
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
|
# Set up the mock to raise ConnectionError on the first call
|
||||||
mock_chat_completion_create.side_effect = [requests.exceptions.ConnectionError("Connection error"), None]
|
# 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
|
# Call the send_with_retries method
|
||||||
coder.send_with_retries("model", ["message"])
|
coder.send_with_retries("model", ["message"])
|
||||||
|
@ -160,5 +164,6 @@ class TestCoder(unittest.TestCase):
|
||||||
# Assert that time.sleep was called once
|
# Assert that time.sleep was called once
|
||||||
mock_sleep.assert_called_once()
|
mock_sleep.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue