we don't want badreq errors bubbling out of Coder.run()

This commit is contained in:
Paul Gauthier 2024-06-27 15:26:40 -07:00
parent e3805350c9
commit 6f31450b90

View file

@ -1,16 +1,15 @@
import tempfile import tempfile
import unittest import unittest
from pathlib import Path from pathlib import Path
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock
import git import git
import openai
from aider.coders import Coder from aider.coders import Coder
from aider.dump import dump # noqa: F401 from aider.dump import dump # noqa: F401
from aider.io import InputOutput from aider.io import InputOutput
from aider.models import Model from aider.models import Model
from aider.utils import ChdirTemporaryDirectory, GitTemporaryDirectory from aider.utils import GitTemporaryDirectory
class TestCoder(unittest.TestCase): class TestCoder(unittest.TestCase):
@ -330,25 +329,6 @@ class TestCoder(unittest.TestCase):
# both files should still be here # both files should still be here
self.assertEqual(len(coder.abs_fnames), 2) self.assertEqual(len(coder.abs_fnames), 2)
def test_run_with_invalid_request_error(self):
with ChdirTemporaryDirectory():
# Mock the IO object
mock_io = MagicMock()
# Initialize the Coder object with the mocked IO and mocked repo
coder = Coder.create(self.GPT35, None, mock_io)
# Call the run method and assert that InvalidRequestError is raised
with self.assertRaises(openai.BadRequestError):
with patch("litellm.completion") as Mock:
Mock.side_effect = openai.BadRequestError(
message="Invalid request",
response=MagicMock(),
body=None,
)
coder.run(with_message="hi")
def test_new_file_edit_one_commit(self): def test_new_file_edit_one_commit(self):
"""A new file shouldn't get pre-committed before the GPT edit commit""" """A new file shouldn't get pre-committed before the GPT edit commit"""
with GitTemporaryDirectory(): with GitTemporaryDirectory():