Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_normal_str(self, platform, value, replace_text, expected):
sanitized_name = sanitize_filepath(value, platform=platform, replacement_text=replace_text)
assert sanitized_name == expected
assert isinstance(sanitized_name, str)
validate_filepath(sanitized_name, platform=platform)
assert is_valid_filepath(sanitized_name, platform=platform)
def test_normal(self, value):
validate_filepath(value, platform="windows")
assert is_valid_filepath(value, platform="windows")
def test_exception_escape_err_msg(self, value, platform, expected):
with pytest.raises(ValidationError) as e:
print(platform, repr(value))
validate_filepath(value, platform=platform)
assert e.value.reason == expected
assert str(e.value) == (
r"invalid char found: invalids=('\r'), value='asdf\rsdf', "
"reason=INVALID_CHARACTER, target-platform=Windows"
def test_exception(self, value, platform, expected):
with pytest.raises(ValidationError) as e:
validate_filepath(value, platform=platform)
assert e.value.reason == expected
assert not is_valid_filepath(value, platform=platform)
def test_normal_rel_path(self, test_platform, value, expected):
if expected is None:
validate_filepath(value, platform=test_platform)
assert is_valid_filepath(value, platform=test_platform)
else:
with pytest.raises(expected):
validate_filepath(value, platform=test_platform)
def test_normal_abs_path(self, test_platform, value, expected):
if expected is None:
validate_filepath(value, platform=test_platform)
assert is_valid_filepath(value, platform=test_platform)
return
with pytest.raises(expected):
validate_filepath(value, platform=test_platform)
def test_normal_pathlike(self, value, replace_text, expected):
sanitized_name = sanitize_filepath(value, replace_text)
assert sanitized_name == expected
assert is_pathlike_obj(sanitized_name)
validate_filepath(sanitized_name)
assert is_valid_filepath(sanitized_name)
def test_minmax_len(self, value, min_len, max_len, expected):
if expected is None:
validate_filepath(value, min_len=min_len, max_len=max_len)
assert is_valid_filepath(value, min_len=min_len, max_len=max_len)
return
with pytest.raises(expected):
validate_filepath(value, min_len=min_len, max_len=max_len)
def test_normal_auto_platform_win(self, value, expected):
if expected is None:
validate_filepath(value, platform="auto")
assert is_valid_filepath(value, platform="auto")
return
with pytest.raises(expected):
validate_filepath(value, platform="auto")
def validate(self):
try:
pv.validate_filepath(self.source, platform="auto")
except pv.ValidationError as e:
raise InvalidFilePathError(e)
if os.path.isfile(self.source) or is_fifo(self.source):
return
raise OSError("file not found")