def check_file_existence(path): """ :return: FileType :rtype: int :raises InvalidFilePathError: :raises FileNotFoundError: :raises RuntimeError: """ pathvalidate.validate_file_path(path) if not os.path.lexists(path): raise FileNotFoundError(path) if os.path.isfile(path): logger.debug("file found: " + path) return FileType.FILE if os.path.isdir(path): logger.debug("directory found: " + path) return FileType.DIRECTORY if os.path.islink(path): logger.debug("link found: " + path) return FileType.LINK raise RuntimeError()
def validate(self): try: pv.validate_file_path(self.source) except pv.NullNameError: raise InvalidFilePathError("file path is empty") except (ValueError, pv.InvalidCharError, pv.InvalidLengthError) as e: raise InvalidFilePathError(e) if not os.path.isfile(self.source): raise IOError("file not found")
def test_normal_multibyte(self, value, replace_text, expected): sanitized_name = sanitize_file_path(value, replace_text) assert sanitized_name == expected validate_file_path(sanitized_name)
def test_exception(self, value, expected): with pytest.raises(expected): validate_file_path(value)
def test_normal(self, value): validate_file_path(value)
def test_exception_invalid_win_char(self, value): with pytest.raises(InvalidCharWindowsError): validate_file_path(value, platform_name="windows")
def test_exception_invalid_char(self, value): with pytest.raises(InvalidCharError): validate_file_path(value)
def test_normal_max_path_len(self, value, platform_name, max_path_len, expected): if expected is None: validate_file_path(value, platform_name=platform_name, max_path_len=max_path_len) else: with pytest.raises(expected): validate_file_path(value, platform_name=platform_name, max_path_len=max_path_len)
def test_normal_win(self, value): validate_file_path(value, "windows")
def test_normal_multibyte(self, value, platform_name): validate_file_path(value, platform_name)