mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-27 15:55:00 +00:00
aider: Add test for setup_git
function.
# Aider chat conversation: USER: add tests for `setup_git` ASSISTANT: To add tests for the `setup_git` function, we need to modify the `tests/test_main.py` file. We will add a new test function `test_setup_git` in the `TestMain` class. Here is the change: ```python tests/test_main.py <<<<<<< ORIGINAL def test_main_args(self): with patch("aider.main.Coder.create") as MockCoder: # --yes will just ok the git repo without blocking on input # following calls to main will see the new repo already main(["--no-auto-commits", "--yes"], input=DummyInput()) _, kwargs = MockCoder.call_args assert kwargs["auto_commits"] is False ======= def test_main_args(self): with patch("aider.main.Coder.create") as MockCoder: # --yes will just ok the git repo without blocking on input # following calls to main will see the new repo already main(["--no-auto-commits", "--yes"], input=DummyInput()) _, kwargs = MockCoder.call_args assert kwargs["auto_commits"] is False def test_setup_git(self): with patch("aider.main.git.Repo.init") as MockRepoInit: MockRepoInit.return_value = git.Repo(self.tempdir) git_root = setup_git(None, self.io) self.assertEqual(git_root, self.tempdir) MockRepoInit.assert_called_once_with(self.tempdir) >>>>>>> UPDATED ``` In the new test `test_setup_git`, we are mocking the `git.Repo.init` function to return a git repository at `self.tempdir`. Then we call `setup_git` with `None` as the `git_root` and check if it returns `self.tempdir` as the new `git_root`. We also check if `git.Repo.init` was called once with `self.tempdir` as the argument.
This commit is contained in:
parent
b0ec8205f3
commit
c8d69f84ce
1 changed files with 7 additions and 0 deletions
|
@ -83,6 +83,13 @@ class TestMain(TestCase):
|
|||
_, kwargs = MockCoder.call_args
|
||||
assert kwargs["auto_commits"] is False
|
||||
|
||||
def test_setup_git(self):
|
||||
with patch("aider.main.git.Repo.init") as MockRepoInit:
|
||||
MockRepoInit.return_value = git.Repo(self.tempdir)
|
||||
git_root = setup_git(None, self.io)
|
||||
self.assertEqual(git_root, self.tempdir)
|
||||
MockRepoInit.assert_called_once_with(self.tempdir)
|
||||
|
||||
with patch("aider.main.Coder.create") as MockCoder:
|
||||
main(["--auto-commits"], input=DummyInput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue