mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
refactor: move test_cmd_save_and_load to test_commands.py
This commit is contained in:
parent
5876af4e94
commit
18c41b6128
2 changed files with 52 additions and 52 deletions
|
@ -1293,58 +1293,6 @@ class Commands:
|
||||||
self.io.tool_error(f"Error saving commands to file: {e}")
|
self.io.tool_error(f"Error saving commands to file: {e}")
|
||||||
|
|
||||||
|
|
||||||
#ai move this to test_commands.py!
|
|
||||||
def test_cmd_save_and_load(self):
|
|
||||||
with GitTemporaryDirectory() as repo_dir:
|
|
||||||
io = InputOutput(pretty=False, fancy_input=False, yes=True)
|
|
||||||
coder = Coder.create(self.GPT35, None, io)
|
|
||||||
commands = Commands(io, coder)
|
|
||||||
|
|
||||||
# Create some test files
|
|
||||||
test_files = {
|
|
||||||
"file1.txt": "Content of file 1",
|
|
||||||
"file2.py": "print('Content of file 2')",
|
|
||||||
"subdir/file3.md": "# Content of file 3"
|
|
||||||
}
|
|
||||||
|
|
||||||
for file_path, content in test_files.items():
|
|
||||||
full_path = Path(repo_dir) / file_path
|
|
||||||
full_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
full_path.write_text(content)
|
|
||||||
|
|
||||||
# Add some files as editable and some as read-only
|
|
||||||
commands.cmd_add("file1.txt file2.py")
|
|
||||||
commands.cmd_read_only("subdir/file3.md")
|
|
||||||
|
|
||||||
# Save the session to a file
|
|
||||||
session_file = "test_session.txt"
|
|
||||||
commands.cmd_save(session_file)
|
|
||||||
|
|
||||||
# Verify the session file was created and contains the expected commands
|
|
||||||
self.assertTrue(Path(session_file).exists())
|
|
||||||
with open(session_file, encoding=io.encoding) as f:
|
|
||||||
commands_text = f.read()
|
|
||||||
self.assertIn("/add file1.txt", commands_text)
|
|
||||||
self.assertIn("/add file2.py", commands_text)
|
|
||||||
self.assertIn("/read-only subdir/file3.md", commands_text)
|
|
||||||
|
|
||||||
# Clear the current session
|
|
||||||
commands.cmd_reset("")
|
|
||||||
self.assertEqual(len(coder.abs_fnames), 0)
|
|
||||||
self.assertEqual(len(coder.abs_read_only_fnames), 0)
|
|
||||||
|
|
||||||
# Load the session back
|
|
||||||
commands.cmd_load(session_file)
|
|
||||||
|
|
||||||
# Verify files were restored correctly
|
|
||||||
added_files = {coder.get_rel_fname(f) for f in coder.abs_fnames}
|
|
||||||
read_only_files = {coder.get_rel_fname(f) for f in coder.abs_read_only_fnames}
|
|
||||||
|
|
||||||
self.assertEqual(added_files, {"file1.txt", "file2.py"})
|
|
||||||
self.assertEqual(read_only_files, {"subdir/file3.md"})
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
Path(session_file).unlink()
|
|
||||||
|
|
||||||
def cmd_copy(self, args):
|
def cmd_copy(self, args):
|
||||||
"Copy the last assistant message to the clipboard"
|
"Copy the last assistant message to the clipboard"
|
||||||
|
|
|
@ -642,6 +642,58 @@ class TestCommands(TestCase):
|
||||||
del commands
|
del commands
|
||||||
del repo
|
del repo
|
||||||
|
|
||||||
|
def test_cmd_save_and_load(self):
|
||||||
|
with GitTemporaryDirectory() as repo_dir:
|
||||||
|
io = InputOutput(pretty=False, fancy_input=False, yes=True)
|
||||||
|
coder = Coder.create(self.GPT35, None, io)
|
||||||
|
commands = Commands(io, coder)
|
||||||
|
|
||||||
|
# Create some test files
|
||||||
|
test_files = {
|
||||||
|
"file1.txt": "Content of file 1",
|
||||||
|
"file2.py": "print('Content of file 2')",
|
||||||
|
"subdir/file3.md": "# Content of file 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
for file_path, content in test_files.items():
|
||||||
|
full_path = Path(repo_dir) / file_path
|
||||||
|
full_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
full_path.write_text(content)
|
||||||
|
|
||||||
|
# Add some files as editable and some as read-only
|
||||||
|
commands.cmd_add("file1.txt file2.py")
|
||||||
|
commands.cmd_read_only("subdir/file3.md")
|
||||||
|
|
||||||
|
# Save the session to a file
|
||||||
|
session_file = "test_session.txt"
|
||||||
|
commands.cmd_save(session_file)
|
||||||
|
|
||||||
|
# Verify the session file was created and contains the expected commands
|
||||||
|
self.assertTrue(Path(session_file).exists())
|
||||||
|
with open(session_file, encoding=io.encoding) as f:
|
||||||
|
commands_text = f.read()
|
||||||
|
self.assertIn("/add file1.txt", commands_text)
|
||||||
|
self.assertIn("/add file2.py", commands_text)
|
||||||
|
self.assertIn("/read-only subdir/file3.md", commands_text)
|
||||||
|
|
||||||
|
# Clear the current session
|
||||||
|
commands.cmd_reset("")
|
||||||
|
self.assertEqual(len(coder.abs_fnames), 0)
|
||||||
|
self.assertEqual(len(coder.abs_read_only_fnames), 0)
|
||||||
|
|
||||||
|
# Load the session back
|
||||||
|
commands.cmd_load(session_file)
|
||||||
|
|
||||||
|
# Verify files were restored correctly
|
||||||
|
added_files = {coder.get_rel_fname(f) for f in coder.abs_fnames}
|
||||||
|
read_only_files = {coder.get_rel_fname(f) for f in coder.abs_read_only_fnames}
|
||||||
|
|
||||||
|
self.assertEqual(added_files, {"file1.txt", "file2.py"})
|
||||||
|
self.assertEqual(read_only_files, {"subdir/file3.md"})
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
Path(session_file).unlink()
|
||||||
|
|
||||||
def test_cmd_read_only_with_glob_pattern(self):
|
def test_cmd_read_only_with_glob_pattern(self):
|
||||||
with GitTemporaryDirectory() as repo_dir:
|
with GitTemporaryDirectory() as repo_dir:
|
||||||
io = InputOutput(pretty=False, fancy_input=False, yes=False)
|
io = InputOutput(pretty=False, fancy_input=False, yes=False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue