mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
aider: Added a new test to check if the --no-auto-commits
flag is passed correctly to the Coder
class.
# Context: USER: add a test which runs main with --no-auto-commits and mocks Coder to see that it gets passed in correctly ASSISTANT: To add the test, we'll modify the `tests/test_main.py` file. We'll create a new test function called `test_main_no_auto_commits` and use the `unittest.mock.patch` to mock the `Coder` class. Inside the test function, we'll run the `main` function with the `--no-auto-commits` flag and check if the `auto_commits` attribute of the mocked `Coder` instance is set to `False`. Here's the change: ```python tests/test_main.py <<<<<<< ORIGINAL def test_main_with_empty_git_dir_new_file(self): with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) subprocess.run(["git", "init"], cwd=temp_dir) 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_with_empty_git_dir_new_file(self): with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) subprocess.run(["git", "init"], cwd=temp_dir) 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_no_auto_commits(self): with unittest.mock.patch("aider.main.Coder") as MockCoder: with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) subprocess.run(["git", "init"], cwd=temp_dir) pipe_input = create_input(StringIO("")) main(["--no-auto-commits"], input=pipe_input, output=DummyOutput()) pipe_input.close() mock_coder_instance = MockCoder.return_value self.assertFalse(mock_coder_instance.auto_commits) >>>>>>> UPDATED ``` This will add the new test to check if the `--no-auto-commits` flag is passed correctly to the `Coder` class.
This commit is contained in:
parent
c33169756a
commit
22482deedf
1 changed files with 12 additions and 0 deletions
|
@ -32,3 +32,15 @@ class TestMain(TestCase):
|
|||
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
|
||||
pipe_input.close()
|
||||
self.assertTrue(os.path.exists("foo.txt"))
|
||||
|
||||
def test_main_no_auto_commits(self):
|
||||
with unittest.mock.patch("aider.main.Coder") as MockCoder:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
os.chdir(temp_dir)
|
||||
subprocess.run(["git", "init"], cwd=temp_dir)
|
||||
pipe_input = create_input(StringIO(""))
|
||||
main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
|
||||
pipe_input.close()
|
||||
|
||||
mock_coder_instance = MockCoder.return_value
|
||||
self.assertFalse(mock_coder_instance.auto_commits)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue