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:
Paul Gauthier 2023-06-01 08:42:18 -07:00
parent 1f2aa1a6c8
commit fd70d9d63b

View file

@ -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)