mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 08:14:59 +00:00
aider: Added setUp and tearDown methods to TestCommands class to remember the current working directory, create a temporary directory, and change the working directory to the temporary directory in setUp, and change the working directory back to the original directory in tearDown.
# Context: USER: add setUp and tearDown. in setUp, make a remember the cwd, make a tempdir and chdir there. in teardown, chdir back to the original dir ASSISTANT: I will add `setUp` and `tearDown` methods to the `TestCommands` class in the `tests/test_commands.py` file. In the `setUp` method, I will ^C KeyboardInterrupt USER: add setUp and tearDown. in setUp, make a remember the cwd, make a tempdir and chdir there. in teardown, chdir back to the original dir ASSISTANT: I will add `setUp` and `tearDown` methods to the `TestCommands` class in the `tests/test_commands.py` file. In the `setUp` method, I will remember the current working directory, create a temporary directory, and change the working directory to the temporary directory. In the `tearDown` method, I will change the working directory back to the original directory. Here are the changes: ```python tests/test_commands.py <<<<<<< ORIGINAL class TestCommands(TestCase): def test_cmd_add(self): ======= import shutil class TestCommands(TestCase): def setUp(self): self.original_cwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) def tearDown(self): os.chdir(self.original_cwd) shutil.rmtree(self.tempdir) def test_cmd_add(self): >>>>>>> UPDATED ```
This commit is contained in:
parent
bb969c7197
commit
e50fe2469d
1 changed files with 21 additions and 18 deletions
|
@ -4,26 +4,29 @@ from unittest import TestCase
|
|||
from aider.commands import Commands
|
||||
from aider.io import InputOutput
|
||||
|
||||
import shutil
|
||||
|
||||
class TestCommands(TestCase):
|
||||
def setUp(self):
|
||||
self.original_cwd = os.getcwd()
|
||||
self.tempdir = tempfile.mkdtemp()
|
||||
os.chdir(self.tempdir)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.original_cwd)
|
||||
shutil.rmtree(self.tempdir)
|
||||
|
||||
def test_cmd_add(self):
|
||||
original_cwd = os.getcwd()
|
||||
# Initialize the Commands and InputOutput objects
|
||||
io = InputOutput(pretty=False, yes=True)
|
||||
from aider.coder import Coder
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
os.chdir(tmpdir)
|
||||
coder = Coder(io, openai_api_key="deadbeef")
|
||||
commands = Commands(io, coder)
|
||||
|
||||
# Initialize the Commands and InputOutput objects
|
||||
io = InputOutput(pretty=False, yes=True)
|
||||
from aider.coder import Coder
|
||||
# Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
|
||||
commands.cmd_add("foo.txt bar.txt")
|
||||
|
||||
coder = Coder(io, openai_api_key="deadbeef")
|
||||
commands = Commands(io, coder)
|
||||
|
||||
# Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
|
||||
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"))
|
||||
|
||||
# The working directory is automatically restored after the context manager exits
|
||||
assert os.getcwd() == original_cwd
|
||||
# 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