def check_requested_output_file(options): if options.output_file == '-': if sys.stdout.isatty(): raise BadArgsError( "Output was set to stdout '-' but it looks like stdout " "is connected to a terminal. Please redirect stdout to a " "file.") elif not is_file_writable(options.output_file): raise OutputFileAccessError( f"Output file location ({options.output_file}) is not a writable file." )
def test_permission_error(self, basic_file): pathmock = MagicMock(spec_set=basic_file) pathmock.is_symlink.return_value = False pathmock.exists.return_value = True pathmock.is_file.side_effect = PermissionError assert not helpers.is_file_writable(pathmock)
def test_chmod(self, basic_file): assert helpers.is_file_writable(basic_file) basic_file.chmod(0o400) assert not helpers.is_file_writable(basic_file) basic_file.chmod(0o000) assert not helpers.is_file_writable(basic_file)
def test_symlink_loop(self, tmp_path): loop = tmp_path / 'loop' loop.symlink_to(loop) assert not helpers.is_file_writable(loop)
def test_plain(self, non_existent): assert helpers.is_file_writable(non_existent)