mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
feat: use GitTemporaryDirectory in test_cmd_add_read_only_file
This commit is contained in:
parent
42d16ebb99
commit
1e8be8a429
1 changed files with 31 additions and 33 deletions
|
@ -538,48 +538,46 @@ class TestCommands(TestCase):
|
||||||
self.assertEqual(coder.abs_fnames, set())
|
self.assertEqual(coder.abs_fnames, set())
|
||||||
|
|
||||||
def test_cmd_add_read_only_file(self):
|
def test_cmd_add_read_only_file(self):
|
||||||
# Initialize the Commands and InputOutput objects
|
with GitTemporaryDirectory():
|
||||||
io = InputOutput(pretty=False, yes=True)
|
# Initialize the Commands and InputOutput objects
|
||||||
from aider.coders import Coder
|
io = InputOutput(pretty=False, yes=True)
|
||||||
|
from aider.coders import Coder
|
||||||
|
|
||||||
coder = Coder.create(self.GPT35, None, io)
|
coder = Coder.create(self.GPT35, None, io)
|
||||||
commands = Commands(io, coder)
|
commands = Commands(io, coder)
|
||||||
|
|
||||||
# Create a test file
|
# Create a test file
|
||||||
test_file = Path("test_read_only.txt")
|
test_file = Path("test_read_only.txt")
|
||||||
test_file.write_text("Test content")
|
test_file.write_text("Test content")
|
||||||
|
|
||||||
# Add the file as read-only
|
# Add the file as read-only
|
||||||
commands.cmd_read(str(test_file))
|
commands.cmd_read(str(test_file))
|
||||||
|
|
||||||
# Verify it's in abs_read_only_fnames
|
# Verify it's in abs_read_only_fnames
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
any(
|
any(
|
||||||
os.path.samefile(str(test_file.resolve()), fname)
|
os.path.samefile(str(test_file.resolve()), fname)
|
||||||
for fname in coder.abs_read_only_fnames
|
for fname in coder.abs_read_only_fnames
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Mock the repo to simulate a tracked file
|
# Mock the repo to simulate a tracked file
|
||||||
coder.repo = mock.MagicMock()
|
coder.repo = mock.MagicMock()
|
||||||
coder.repo.is_tracked_file.return_value = True
|
coder.repo.is_tracked_file.return_value = True
|
||||||
|
|
||||||
# Try to add the read-only file
|
# Try to add the read-only file
|
||||||
commands.cmd_add(str(test_file))
|
commands.cmd_add(str(test_file))
|
||||||
|
|
||||||
# Verify it's now in abs_fnames and not in abs_read_only_fnames
|
# Verify it's now in abs_fnames and not in abs_read_only_fnames
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
any(os.path.samefile(str(test_file.resolve()), fname) for fname in coder.abs_fnames)
|
any(os.path.samefile(str(test_file.resolve()), fname) for fname in coder.abs_fnames)
|
||||||
)
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
any(
|
any(
|
||||||
os.path.samefile(str(test_file.resolve()), fname)
|
os.path.samefile(str(test_file.resolve()), fname)
|
||||||
for fname in coder.abs_read_only_fnames
|
for fname in coder.abs_read_only_fnames
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
test_file.unlink()
|
|
||||||
|
|
||||||
def test_cmd_test_unbound_local_error(self):
|
def test_cmd_test_unbound_local_error(self):
|
||||||
with ChdirTemporaryDirectory():
|
with ChdirTemporaryDirectory():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue