@@ -345,6 +345,33 @@ def mock_stat(path, *args, **kwargs):
345345 assert "Error" not in caplog .text
346346 assert "disappearing.txt" not in caplog .text
347347
348+ def test_error_creating_symlink (self , temp_dirs , caplog ):
349+ """Test error message when symlink creation fails."""
350+ source_dir , target_dir = temp_dirs
351+ username = os .environ ["USER" ]
352+
353+ # Create source file
354+ source_file = os .path .join (source_dir , "test.txt" )
355+ target_file = os .path .join (target_dir , "test.txt" )
356+
357+ with open (source_file , "w" , encoding = "utf-8" ) as f :
358+ f .write ("source" )
359+ with open (target_file , "w" , encoding = "utf-8" ) as f :
360+ f .write ("target" )
361+
362+ # Mock os.symlink to raise an error
363+ def mock_symlink (src , dst ):
364+ raise OSError ("Simulated symlink error" )
365+
366+ with patch ("os.symlink" , side_effect = mock_symlink ):
367+ # Run the function
368+ with caplog .at_level (logging .INFO ):
369+ relink .find_and_replace_owned_files (source_dir , target_dir , username )
370+
371+ # Check error message
372+ assert "Error creating symlink" in caplog .text
373+ assert source_file in caplog .text
374+
348375
349376class TestParseArguments :
350377 """Test suite for parse_arguments function."""
0 commit comments