Exemple #1
0
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()
Exemple #2
0
    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")
Exemple #3
0
 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)
Exemple #4
0
 def test_exception(self, value, expected):
     with pytest.raises(expected):
         validate_file_path(value)
Exemple #5
0
 def test_normal(self, value):
     validate_file_path(value)
Exemple #6
0
 def test_exception_invalid_win_char(self, value):
     with pytest.raises(InvalidCharWindowsError):
         validate_file_path(value, platform_name="windows")
Exemple #7
0
 def test_exception_invalid_char(self, value):
     with pytest.raises(InvalidCharError):
         validate_file_path(value)
Exemple #8
0
 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)
Exemple #9
0
 def test_normal_win(self, value):
     validate_file_path(value, "windows")
Exemple #10
0
 def test_normal_multibyte(self, value, platform_name):
     validate_file_path(value, platform_name)