mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 00:05:01 +00:00
aider: Added a test for cmd_add
that passes in 'foo.txt' and 'bar.txt' and ensures they have both been created after the test.
# Context: USER: add a test for cmd_add that passes in 'foo.txt' and 'bar.txt' and ensures they have both been created after the test. run the test in a tmp dir. ASSISTANT: To add the test for `cmd_add`, we will modify the `tests/test_commands.py` file. Here's the step-by-step plan: 1. Import the necessary libraries and classes. 2. Create a new test method called `test_cmd_add` inside the `TestCommands` class. 3. In the `test_cmd_add` method, create a temporary directory using `tempfile.TemporaryDirectory`. 4. Change the current working directory to the temporary directory. 5. Create an instance of the `InputOutput` and `Coder` classes. 6. Create an instance of the `Commands` class, passing the `InputOutput` and `Coder` instances. 7. Call the `cmd_add` method with the arguments `['foo.txt', 'bar.txt']`. 8. Check if both 'foo.txt' and 'bar.txt' files have been created in the temporary directory. 9. Change the current working directory back to the original directory. Here's the code change: ```python tests/test_commands.py <<<<<<< ORIGINAL ======= import os import tempfile from unittest import TestCase from aider.io import InputOutput from aider.coder import Coder from aider.commands import Commands class TestCommands(TestCase): def test_cmd_add(self): with tempfile.TemporaryDirectory() as tmpdir: original_cwd = os.getcwd() os.chdir(tmpdir) io = InputOutput() coder = Coder(io) commands = Commands(io, coder) commands.cmd_add(['foo.txt', 'bar.txt']) self.assertTrue(os.path.exists('foo.txt')) self.assertTrue(os.path.exists('bar.txt')) os.chdir(original_cwd) >>>>>>> UPDATED ``` This will add the test for `cmd_add` and ensure that both 'foo.txt' and 'bar.txt' have been created after the test.
This commit is contained in:
parent
73853d42ce
commit
922d28216a
1 changed files with 23 additions and 0 deletions
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
from aider.io import InputOutput
|
||||
from aider.coder import Coder
|
||||
from aider.commands import Commands
|
||||
|
||||
class TestCommands(TestCase):
|
||||
def test_cmd_add(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
original_cwd = os.getcwd()
|
||||
os.chdir(tmpdir)
|
||||
|
||||
io = InputOutput()
|
||||
coder = Coder(io)
|
||||
commands = Commands(io, coder)
|
||||
|
||||
commands.cmd_add(['foo.txt', 'bar.txt'])
|
||||
|
||||
self.assertTrue(os.path.exists('foo.txt'))
|
||||
self.assertTrue(os.path.exists('bar.txt'))
|
||||
|
||||
os.chdir(original_cwd)
|
Loading…
Add table
Add a link
Reference in a new issue