mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 13:54:59 +00:00
aider: Added a test method test_cmd_add
that creates a temporary directory, calls the cmd_add
method with 'foo.txt' and 'bar.txt', and checks if both files have been created in the temporary directory.
# 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: I will add a new test method called `test_cmd_add` in the `tests/test_commands.py` file. This test will create a temporary directory, change the current working directory to the temporary directory, and then call the `cmd_add` method with 'foo.txt' and 'bar.txt' as arguments. After that, it will check if both files have been created in the temporary directory. Here's the code change: ```python tests/test_commands.py <<<<<<< ORIGINAL ======= import os import tempfile from unittest import TestCase from unittest.mock import MagicMock from aider.commands import Commands from aider.io import InputOutput class TestCommands(TestCase): def test_cmd_add(self): # Create a temporary directory and change the current working directory with tempfile.TemporaryDirectory() as tmpdir: os.chdir(tmpdir) # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True) coder = MagicMock() commands = Commands(io, coder) # Call the cmd_add method with 'foo.txt' and 'bar.txt' commands.cmd_add(["foo.txt", "bar.txt"]) # Check if both files have been created in the temporary directory self.assertTrue(os.path.exists("foo.txt")) self.assertTrue(os.path.exists("bar.txt")) >>>>>>> UPDATED ``` This test will ensure that the `cmd_add` method creates the specified files in the current working directory.
This commit is contained in:
parent
b9cea2cdb1
commit
e2d5212eec
1 changed files with 24 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
|||
import os
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock
|
||||
from aider.commands import Commands
|
||||
from aider.io import InputOutput
|
||||
|
||||
class TestCommands(TestCase):
|
||||
def test_cmd_add(self):
|
||||
# Create a temporary directory and change the current working directory
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
os.chdir(tmpdir)
|
||||
|
||||
# Initialize the Commands and InputOutput objects
|
||||
io = InputOutput(pretty=False, yes=True)
|
||||
coder = MagicMock()
|
||||
commands = Commands(io, coder)
|
||||
|
||||
# Call the cmd_add method with 'foo.txt' and 'bar.txt'
|
||||
commands.cmd_add(["foo.txt", "bar.txt"])
|
||||
|
||||
# Check if both files have been created in the temporary directory
|
||||
self.assertTrue(os.path.exists("foo.txt"))
|
||||
self.assertTrue(os.path.exists("bar.txt"))
|
Loading…
Add table
Add a link
Reference in a new issue