mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04:59 +00:00

# 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.
23 lines
642 B
Python
23 lines
642 B
Python
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)
|