mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04:59 +00:00
refactor: improve path comparison in command tests using os.path.samefile
This commit is contained in:
parent
d06c6f8557
commit
be54df4084
1 changed files with 24 additions and 4 deletions
|
@ -671,10 +671,30 @@ class TestCommands(TestCase):
|
|||
# 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)
|
||||
commands_text = f.read().splitlines()
|
||||
|
||||
# Convert paths to absolute for comparison
|
||||
abs_file1 = str(Path("file1.txt").resolve())
|
||||
abs_file2 = str(Path("file2.py").resolve())
|
||||
abs_file3 = str(Path("subdir/file3.md").resolve())
|
||||
|
||||
# Check each line for matching paths using os.path.samefile
|
||||
found_file1 = found_file2 = found_file3 = False
|
||||
for line in commands_text:
|
||||
if line.startswith("/add "):
|
||||
path = Path(line[5:]).resolve()
|
||||
if os.path.samefile(str(path), abs_file1):
|
||||
found_file1 = True
|
||||
elif os.path.samefile(str(path), abs_file2):
|
||||
found_file2 = True
|
||||
elif line.startswith("/read-only "):
|
||||
path = Path(line[11:]).resolve()
|
||||
if os.path.samefile(str(path), abs_file3):
|
||||
found_file3 = True
|
||||
|
||||
self.assertTrue(found_file1, "file1.txt not found in commands")
|
||||
self.assertTrue(found_file2, "file2.py not found in commands")
|
||||
self.assertTrue(found_file3, "file3.md not found in commands")
|
||||
|
||||
# Clear the current session
|
||||
commands.cmd_reset("")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue