fixed test_commands

This commit is contained in:
Paul Gauthier 2024-04-18 15:01:02 -07:00
parent 67cc974454
commit f960774b51
2 changed files with 26 additions and 28 deletions

View file

@ -117,6 +117,7 @@ class Model:
edit_format = "whole"
use_repo_map = False
send_undo_reply = False
accepts_images = False
max_chat_history_tokens = 1024
weak_model = None

View file

@ -6,15 +6,14 @@ import tempfile
from io import StringIO
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
import git
from aider import models
from aider.coders import Coder
from aider.commands import Commands
from aider.dump import dump # noqa: F401
from aider.io import InputOutput
from aider.models import Model
from aider.utils import ChdirTemporaryDirectory, GitTemporaryDirectory, make_repo
@ -24,9 +23,7 @@ class TestCommands(TestCase):
self.tempdir = tempfile.mkdtemp()
os.chdir(self.tempdir)
self.patcher = patch("aider.coders.base_coder.check_model_availability")
self.mock_check = self.patcher.start()
self.mock_check.return_value = True
self.GPT35 = Model("gpt-3.5-turbo")
def tearDown(self):
os.chdir(self.original_cwd)
@ -37,7 +34,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
@ -53,7 +50,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
commands.cmd_add("**.txt")
@ -63,7 +60,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Create some test files
@ -89,7 +86,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Call the cmd_add method with a non-existent file pattern
@ -103,7 +100,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("[abc].nonexistent")
@ -120,7 +117,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Create a directory and add files to it using pathlib
@ -171,7 +168,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
subdir = Path("subdir")
@ -198,7 +195,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Create a new file foo.bad which will fail to decode as utf-8
@ -218,7 +215,7 @@ class TestCommands(TestCase):
with open(f"{tempdir}/test.txt", "w") as f:
f.write("test")
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Run the cmd_git method with the arguments "commit -a -m msg"
@ -234,7 +231,7 @@ class TestCommands(TestCase):
# Initialize the Commands and InputOutput objects
io = InputOutput(pretty=False, yes=True)
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
commands.cmd_add("foo.txt bar.txt")
@ -275,7 +272,7 @@ class TestCommands(TestCase):
os.chdir("subdir")
io = InputOutput(pretty=False, yes=True)
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# this should get added
@ -293,7 +290,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
Path("side_dir").mkdir()
@ -317,7 +314,7 @@ class TestCommands(TestCase):
repo.git.commit("-m", "initial")
io = InputOutput(pretty=False, yes=True)
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
self.assertFalse(repo.is_dirty())
@ -338,7 +335,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
outside_file = Path(tmp_dname) / "outside.txt"
@ -361,7 +358,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
outside_file = Path(tmp_dname) / "outside.txt"
@ -379,7 +376,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("with[brackets].txt")
@ -394,7 +391,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("file.txt")
@ -409,7 +406,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("file with spaces.txt")
@ -437,7 +434,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# There's no reason this /add should trigger a commit
@ -460,7 +457,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
fname = "file.txt"
@ -479,7 +476,7 @@ class TestCommands(TestCase):
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("test.txt")
@ -502,7 +499,7 @@ class TestCommands(TestCase):
with GitTemporaryDirectory() as repo_dir:
repo = git.Repo(repo_dir)
io = InputOutput(pretty=False, yes=True)
coder = Coder.create(models.GPT35, None, io)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
other_path = Path(repo_dir) / "other_file.txt"
@ -563,7 +560,7 @@ class TestCommands(TestCase):
io = InputOutput(yes=True)
coder = Coder.create(
models.GPT4, None, io, fnames=[fname1, fname2], aider_ignore_file=str(aignore)
self.GPT35, None, io, fnames=[fname1, fname2], aider_ignore_file=str(aignore)
)
commands = Commands(io, coder)