mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00

# 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`.
88 lines
3 KiB
Python
88 lines
3 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
from io import StringIO
|
|
from unittest import TestCase
|
|
from unittest.mock import patch
|
|
|
|
from prompt_toolkit.input import create_input
|
|
from prompt_toolkit.output import DummyOutput
|
|
|
|
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)
|
|
|
|
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)
|
|
shutil.rmtree(self.tempdir)
|
|
|
|
def test_main_with_empty_dir_no_files_on_command(self):
|
|
pipe_input = create_input(StringIO(""))
|
|
main([], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
|
|
def test_main_with_empty_dir_new_file(self):
|
|
pipe_input = create_input(StringIO(""))
|
|
main(["foo.txt"], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
self.assertTrue(os.path.exists("foo.txt"))
|
|
|
|
def test_main_with_empty_git_dir_new_file(self):
|
|
subprocess.run(["git", "init"])
|
|
subprocess.run(["git", "config", "user.email", "dummy@example.com"])
|
|
subprocess.run(["git", "config", "user.name", "Dummy User"])
|
|
pipe_input = create_input(StringIO(""))
|
|
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
self.assertTrue(os.path.exists("foo.txt"))
|
|
|
|
def test_main_args(self):
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main(["--no-auto-commits"])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["auto_commits"] is False
|
|
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main(["--auto-commits"])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["auto_commits"] is True
|
|
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main([])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["dirty_commits"] is True
|
|
assert kwargs["auto_commits"] is True
|
|
assert kwargs["pretty"] is True
|
|
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main(["--no-pretty"])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["pretty"] is False
|
|
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main(["--pretty"])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["pretty"] is True
|
|
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main(["--no-dirty-commits"])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["dirty_commits"] is False
|
|
|
|
with patch("aider.main.Coder") as MockCoder:
|
|
main(["--dirty-commits"])
|
|
_, kwargs = MockCoder.call_args
|
|
assert kwargs["dirty_commits"] is True
|