From fd70d9d63b065db0cafa7a877dedc20df372fef2 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 1 Jun 2023 08:42:18 -0700 Subject: [PATCH] aider: Patched check_for_model_availability to always return True during setUp method execution. # Context: USER: in setup, patch coder.check_for_model_availability to return true ASSISTANT: To patch the `check_for_model_availability` method in the `setUp` method of the `TestMain` class, you can use the `unittest.mock.patch` context manager. Here's the change you need to make in the `tests/test_main.py` file: ```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) ======= from unittest.mock import MagicMock 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.coder.Coder.check_for_model_availability") as mock_check: mock_check.return_value = True self.mock_check = mock_check >>>>>>> UPDATED ``` This will patch the `check_for_model_availability` method to always return `True` during the `setUp` method execution. --- tests/test_main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index eb35435dc..a4116679b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -13,12 +13,18 @@ from aider.main import main class TestMain(TestCase): + from unittest.mock import MagicMock + 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.coder.Coder.check_for_model_availability") as mock_check: + mock_check.return_value = True + self.mock_check = mock_check + def tearDown(self): os.chdir(self.original_cwd) shutil.rmtree(self.tempdir)