tests and bugfix

This commit is contained in:
Paul Gauthier 2023-07-24 17:47:53 -03:00
parent 957f59c011
commit c8f1c0609d
3 changed files with 37 additions and 6 deletions

View file

@ -405,7 +405,7 @@ def main(argv=None, input=None, output=None, force_git_root=None):
dry_run=args.dry_run,
)
fnames = args.files
fnames = [str(Path(fn).resolve()) for fn in args.files]
if len(args.files) > 1:
good = True
for fname in args.files:
@ -422,11 +422,11 @@ def main(argv=None, input=None, output=None, force_git_root=None):
if len(args.files) == 1:
if Path(args.files[0]).is_dir():
if args.git:
git_dname = args.files[0]
git_dname = str(Path(args.files[0]).resolve())
fnames = []
else:
io.tool_error(f"{args.files[0]} is a directory, but --no-git selected.")
return -1
return 1
# We can't know the git repo for sure until after parsing the args.
# If we guessed wrong, reparse because that changes things like
@ -506,7 +506,7 @@ def main(argv=None, input=None, output=None, force_git_root=None):
)
except ValueError as err:
io.tool_error(str(err))
return
return 1
if args.show_repo_map:
repo_map = coder.get_repo_map()

View file

@ -44,6 +44,33 @@ class TestMain(TestCase):
main(["--yes", "foo.txt"], input=DummyInput(), output=DummyOutput())
self.assertTrue(os.path.exists("foo.txt"))
@patch("aider.repo.GitRepo.get_commit_message", return_value="mock commit message")
def test_main_with_empty_git_dir_new_files(self, _):
make_repo()
main(["--yes", "foo.txt", "bar.txt"], input=DummyInput(), output=DummyOutput())
self.assertTrue(os.path.exists("foo.txt"))
self.assertTrue(os.path.exists("bar.txt"))
def test_main_with_dname_and_fname(self):
subdir = Path("subdir")
subdir.mkdir()
make_repo(str(subdir))
res = main(["subdir", "foo.txt"], input=DummyInput(), output=DummyOutput())
self.assertNotEqual(res, None)
@patch("aider.repo.GitRepo.get_commit_message", return_value="mock commit message")
def test_main_with_subdir_repo_fnames(self, _):
subdir = Path("subdir")
subdir.mkdir()
make_repo(str(subdir))
main(
["--yes", str(subdir / "foo.txt"), str(subdir / "bar.txt")],
input=DummyInput(),
output=DummyOutput(),
)
self.assertTrue((subdir / "foo.txt").exists())
self.assertTrue((subdir / "bar.txt").exists())
def test_main_with_git_config_yml(self):
make_repo()

View file

@ -42,7 +42,11 @@ class GitTemporaryDirectory(ChdirTemporaryDirectory):
return res
def make_repo():
repo = git.Repo.init()
def make_repo(path=None):
if not path:
path = "."
repo = git.Repo.init(path)
repo.config_writer().set_value("user", "name", "Test User").release()
repo.config_writer().set_value("user", "email", "testuser@example.com").release()
return repo