mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 05:14:59 +00:00
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.
This commit is contained in:
parent
1f2aa1a6c8
commit
fd70d9d63b
1 changed files with 6 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue