mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 22:04:59 +00:00
aider: The test is modified to include the missing param
argument when raising InvalidRequestError
.
# Aider chat conversation: USER: I ran this command: pytest tests/test_coder.py -k test_run_with_invalid_request_error And got this output: ============================= test session starts ============================== platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0 rootdir: /Users/gauthier/Projects/aider configfile: pytest.ini collected 14 items / 13 deselected / 1 selected tests/test_coder.py F [100%] =================================== FAILURES =================================== ________________ TestCoder.test_run_with_invalid_request_error _________________ self = <tests.test_coder.TestCoder testMethod=test_run_with_invalid_request_error> mock_chat_completion_create = <MagicMock name='create' id='4934396624'> @patch("aider.coders.base_coder.openai.ChatCompletion.create") def test_run_with_invalid_request_error(self, mock_chat_completion_create): # Mock the IO object mock_io = MagicMock() # Initialize the Coder object with the mocked IO and mocked repo coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key") # Set up the mock to raise InvalidRequestError > mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request") E TypeError: InvalidRequestError.__init__() missing 1 required positional argument: 'param' tests/test_coder.py:355: TypeError =========================== short test summary info ============================ FAILED tests/test_coder.py::TestCoder::test_run_with_invalid_request_error - ... ======================= 1 failed, 13 deselected in 1.04s ======================= ASSISTANT: The `openai.error.InvalidRequestError` requires two positional arguments: `message` and `param`. The `param` argument is used to specify the parameter that caused the invalid request. Let's modify the test to include a `param` when raising the `InvalidRequestError`. Here is the change: ```python tests/test_coder.py <<<<<<< ORIGINAL @patch("aider.coders.base_coder.openai.ChatCompletion.create") def test_run_with_invalid_request_error(self, mock_chat_completion_create): # Mock the IO object mock_io = MagicMock() # Initialize the Coder object with the mocked IO and mocked repo coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key") # Set up the mock to raise InvalidRequestError mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request") # Call the run method and assert that InvalidRequestError is raised with self.assertRaises(openai.error.InvalidRequestError): coder.run(with_message="hi") ======= @patch("aider.coders.base_coder.openai.ChatCompletion.create") def test_run_with_invalid_request_error(self, mock_chat_completion_create): # Mock the IO object mock_io = MagicMock() # Initialize the Coder object with the mocked IO and mocked repo coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key") # Set up the mock to raise InvalidRequestError mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request", "param") # Call the run method and assert that InvalidRequestError is raised with self.assertRaises(openai.error.InvalidRequestError): coder.run(with_message="hi") >>>>>>> UPDATED ``` This change should fix the `TypeError` you're seeing in your test run.
This commit is contained in:
parent
d3dac2fac6
commit
3040409590
1 changed files with 1 additions and 1 deletions
|
@ -352,7 +352,7 @@ class TestCoder(unittest.TestCase):
|
|||
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
||||
|
||||
# Set up the mock to raise InvalidRequestError
|
||||
mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request")
|
||||
mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request", "param")
|
||||
|
||||
# Call the run method and assert that InvalidRequestError is raised
|
||||
with self.assertRaises(openai.error.InvalidRequestError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue