feat: add test for check_for_file_mentions with read-only file

This commit is contained in:
Paul Gauthier (aider) 2024-08-12 14:27:17 -07:00
parent cb24f8c6d4
commit 1cc6841bad

View file

@ -189,6 +189,30 @@ class TestCoder(unittest.TestCase):
self.assertEqual(coder.abs_fnames, set([str(fname.resolve())])) self.assertEqual(coder.abs_fnames, set([str(fname.resolve())]))
def test_check_for_file_mentions_read_only(self):
with GitTemporaryDirectory():
io = InputOutput(pretty=False, yes=False) # Set yes=False to simulate user not confirming
coder = Coder.create(self.GPT35, None, io)
fname = Path("readonly_file.txt")
fname.touch()
coder.abs_read_only_fnames.add(str(fname.resolve()))
# Mock the get_tracked_files method
mock = MagicMock()
mock.return_value = set([str(fname)])
coder.repo.get_tracked_files = mock
# Call the check_for_file_mentions method
result = coder.check_for_file_mentions(f"Please check {fname}!")
# Assert that the method returns None (user not asked to add the file)
self.assertIsNone(result)
# Assert that abs_fnames is still empty (file not added)
self.assertEqual(coder.abs_fnames, set())
def test_check_for_subdir_mention(self): def test_check_for_subdir_mention(self):
with GitTemporaryDirectory(): with GitTemporaryDirectory():
io = InputOutput(pretty=False, yes=True) io = InputOutput(pretty=False, yes=True)