From 4a3e8ba41dd8b8cde24dbf5d00597c0102cbc843 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 31 Aug 2024 08:04:14 -0700 Subject: [PATCH] test: add test for Coder.create with OSError on new file --- tests/basic/test_coder.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/basic/test_coder.py b/tests/basic/test_coder.py index 128b21aa3..a04b3c079 100644 --- a/tests/basic/test_coder.py +++ b/tests/basic/test_coder.py @@ -846,6 +846,22 @@ This command will print 'Hello, World!' to the console.""" # Check if handle_shell_commands was called with the correct argument coder.handle_shell_commands.assert_not_called() + def test_coder_create_with_new_file_oserror(self): + with GitTemporaryDirectory(): + io = InputOutput(yes=True) + new_file = "new_file.txt" + + # Mock Path.touch() to raise OSError + with patch('pathlib.Path.touch', side_effect=OSError("Permission denied")): + # Create the coder with a new file + coder = Coder.create(self.GPT35, "diff", io=io, fnames=[new_file]) + + # Check if the coder was created successfully + self.assertIsInstance(coder, Coder) + + # Check if the new file is not in abs_fnames + self.assertNotIn(new_file, [os.path.basename(f) for f in coder.abs_fnames]) + def test_show_exhausted_error(self): with GitTemporaryDirectory(): io = InputOutput(yes=True)