mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 22:04:59 +00:00
style: fix indentation in test_cmd_save_and_load_with_external_file
This commit is contained in:
parent
8d6db81a40
commit
9e9c162a16
1 changed files with 45 additions and 45 deletions
|
@ -695,63 +695,63 @@ class TestCommands(TestCase):
|
||||||
Path(session_file).unlink()
|
Path(session_file).unlink()
|
||||||
|
|
||||||
|
|
||||||
def test_cmd_save_and_load_with_external_file(self):
|
def test_cmd_save_and_load_with_external_file(self):
|
||||||
with tempfile.NamedTemporaryFile(mode="w", delete=False) as external_file:
|
with tempfile.NamedTemporaryFile(mode="w", delete=False) as external_file:
|
||||||
external_file.write("External file content")
|
external_file.write("External file content")
|
||||||
external_file_path = external_file.name
|
external_file_path = external_file.name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with GitTemporaryDirectory() as repo_dir:
|
with GitTemporaryDirectory() as repo_dir:
|
||||||
io = InputOutput(pretty=False, fancy_input=False, yes=True)
|
io = InputOutput(pretty=False, fancy_input=False, yes=True)
|
||||||
coder = Coder.create(self.GPT35, None, io)
|
coder = Coder.create(self.GPT35, None, io)
|
||||||
commands = Commands(io, coder)
|
commands = Commands(io, coder)
|
||||||
|
|
||||||
# Create some test files in the repo
|
# Create some test files in the repo
|
||||||
test_files = {
|
test_files = {
|
||||||
"file1.txt": "Content of file 1",
|
"file1.txt": "Content of file 1",
|
||||||
"file2.py": "print('Content of file 2')",
|
"file2.py": "print('Content of file 2')",
|
||||||
}
|
}
|
||||||
|
|
||||||
for file_path, content in test_files.items():
|
for file_path, content in test_files.items():
|
||||||
full_path = Path(repo_dir) / file_path
|
full_path = Path(repo_dir) / file_path
|
||||||
full_path.parent.mkdir(parents=True, exist_ok=True)
|
full_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
full_path.write_text(content)
|
full_path.write_text(content)
|
||||||
|
|
||||||
# Add some files as editable and some as read-only
|
# Add some files as editable and some as read-only
|
||||||
commands.cmd_add("file1.txt")
|
commands.cmd_add("file1.txt")
|
||||||
commands.cmd_read_only(external_file_path)
|
commands.cmd_read_only(external_file_path)
|
||||||
|
|
||||||
# Save the session to a file
|
# Save the session to a file
|
||||||
session_file = "test_session.txt"
|
session_file = "test_session.txt"
|
||||||
commands.cmd_save(session_file)
|
commands.cmd_save(session_file)
|
||||||
|
|
||||||
# Verify the session file was created and contains the expected commands
|
# Verify the session file was created and contains the expected commands
|
||||||
self.assertTrue(Path(session_file).exists())
|
self.assertTrue(Path(session_file).exists())
|
||||||
with open(session_file, encoding=io.encoding) as f:
|
with open(session_file, encoding=io.encoding) as f:
|
||||||
commands_text = f.read()
|
commands_text = f.read()
|
||||||
self.assertIn("/add file1.txt", commands_text)
|
self.assertIn("/add file1.txt", commands_text)
|
||||||
self.assertIn(f"/read-only {external_file_path}", commands_text)
|
self.assertIn(f"/read-only {external_file_path}", commands_text)
|
||||||
|
|
||||||
# Clear the current session
|
# Clear the current session
|
||||||
commands.cmd_reset("")
|
commands.cmd_reset("")
|
||||||
self.assertEqual(len(coder.abs_fnames), 0)
|
self.assertEqual(len(coder.abs_fnames), 0)
|
||||||
self.assertEqual(len(coder.abs_read_only_fnames), 0)
|
self.assertEqual(len(coder.abs_read_only_fnames), 0)
|
||||||
|
|
||||||
# Load the session back
|
# Load the session back
|
||||||
commands.cmd_load(session_file)
|
commands.cmd_load(session_file)
|
||||||
|
|
||||||
# Verify files were restored correctly
|
# Verify files were restored correctly
|
||||||
added_files = {coder.get_rel_fname(f) for f in coder.abs_fnames}
|
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}
|
read_only_files = {coder.get_rel_fname(f) for f in coder.abs_read_only_fnames}
|
||||||
|
|
||||||
self.assertEqual(added_files, {"file1.txt"})
|
self.assertEqual(added_files, {"file1.txt"})
|
||||||
self.assertEqual(read_only_files, {external_file_path})
|
self.assertEqual(read_only_files, {external_file_path})
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
Path(session_file).unlink()
|
Path(session_file).unlink()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
os.unlink(external_file_path)
|
os.unlink(external_file_path)
|
||||||
|
|
||||||
# ai: add another test for load/save, but include a /read-only file that!
|
# ai: add another test for load/save, but include a /read-only file that!
|
||||||
# is from outside the repo
|
# is from outside the repo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue