def test_replace_in_file_readonly(self): tmp_dir = temp_folder() text_file = os.path.join(tmp_dir, "text.txt") save(text_file, "ONE TWO THREE") os.chmod( text_file, os.stat(text_file).st_mode & ~(stat.S_IWRITE | stat.S_IWGRP | stat.S_IWOTH)) mode_before_replace = os.stat(text_file).st_mode replace_in_file(text_file, "ONE TWO THREE", "FOUR FIVE SIX", output=TestBufferConanOutput()) self.assertEqual(load(text_file), "FOUR FIVE SIX") self.assertEqual(os.stat(text_file).st_mode, mode_before_replace) replace_path_in_file(text_file, "FOUR FIVE SIX", "SEVEN EIGHT NINE", output=TestBufferConanOutput()) self.assertEqual(load(text_file), "SEVEN EIGHT NINE") self.assertEqual(os.stat(text_file).st_mode, mode_before_replace)
def replace_path_in_file(*args, **kwargs): return tools_files.replace_path_in_file(output=_global_output, *args, **kwargs)