From 99693fe614ea0043891e784bed37f66c0f5f98fe Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 1 Jun 2023 08:50:55 -0700 Subject: [PATCH] aider: Modified setUp method to patch check_model_availability with MagicMock object that always returns True. # Context: USER: the patch in `setUp` is not correcting forcing a return of true ASSISTANT: To ensure that the patch in `setUp` correctly forces a return of `True`, you need to modify the `setUp` method in the `TestMain` class in the `tests/test_main.py` file. Here's the change: ```python tests/test_main.py <<<<<<< ORIGINAL def setUp(self): os.environ["OPENAI_API_KEY"] = "deadbeef" self.original_cwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) with patch("aider.main.Coder.check_model_availability") as self.mock_check: self.mock_check.return_value = True super().setUp() ======= def setUp(self): os.environ["OPENAI_API_KEY"] = "deadbeef" self.original_cwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) self.mock_check = MagicMock(return_value=True) with patch("aider.main.Coder.check_model_availability", new=self.mock_check): super().setUp() >>>>>>> UPDATED ``` This change ensures that the `check_model_availability` method is patched with a `MagicMock` object that always returns `True`. --- tests/test_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 9f54a3426..f246e6c21 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,9 +21,9 @@ class TestMain(TestCase): self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) - with patch("aider.main.Coder.check_model_availability") as self.mock_check: - self.mock_check.return_value = True - super().setUp() + self.mock_check = MagicMock(return_value=True) + with patch("aider.main.Coder.check_model_availability", new=self.mock_check): + super().setUp() def tearDown(self): os.chdir(self.original_cwd)