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

# Context: USER: E AttributeError: <class 'aider.coder.Coder'> does not have the attribute 'check_for_model_availability' ASSISTANT: It seems like you are trying to access the `check_for_model_availability` method of the `Coder` class, but it is not defined as an instance method. To fix this issue, you need to move the `check_model_availability` method inside the `Coder` class and update the tests accordingly. Here are the changes you need to make: 1. Move the ` ^C KeyboardInterrupt USER: fix the `setUp` ASSISTANT: To fix the `setUp` method in the `TestMain` class, you need to update the way you are mocking the `check_for_model_availability` method. Here are the changes you need to make: 1. Modify the `setUp` method in the `TestMain` class to correctly mock the `check_for_model_availability` method of the `Coder` class. ```python tests/test_main.py <<<<<<< ORIGINAL with patch("aider.coder.Coder.check_for_model_availability") as mock_check: mock_check.return_value = True self.mock_check = mock_check ======= with patch("aider.coder.Coder.check_model_availability") as mock_check: mock_check.return_value = True self.mock_check = mock_check >>>>>>> UPDATED ``` This change will ensure that the `check_for_model_availability` method is correctly mocked during the tests.
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)
|
|
|
|
with patch("aider.coder.Coder.check_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)
|
|
|
|
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
|