From 30404095903b983ac926670962ba50a2bcc5c319 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 8 Jul 2023 09:27:43 -0700 Subject: [PATCH] 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 = mock_chat_completion_create = @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. --- tests/test_coder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index 39e2647d1..c4f95e06f 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -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):