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_space_or_period_at_tail(self, platform, value, expected):
filename = sanitize_filename(value, platform=platform)
assert filename == expected
assert is_valid_filename(filename, platform=platform)
def test_exception_type(self, value, expected):
with pytest.raises(expected):
sanitize_filename(value)
assert not is_valid_filename(value)
def test_min_len(self, value, min_len, expected):
if expected is None:
validate_filename(value, min_len=min_len)
assert is_valid_filename(value, min_len=min_len)
else:
with pytest.raises(ValidationError) as e:
validate_filename(value, min_len=min_len)
assert e.value.reason == expected
def test_normal_pathlike(self, value, replace_text, expected):
sanitized_name = sanitize_filename(value, replace_text)
assert sanitized_name == expected
assert is_pathlike_obj(sanitized_name)
validate_filename(sanitized_name)
assert is_valid_filename(sanitized_name)
def test_normal(self, value, platform):
validate_filename(value, platform)
assert is_valid_filename(value, platform=platform)
def test_normal_multibyte(self, value, platform):
validate_filename(value, platform)
assert is_valid_filename(value, platform=platform)
def test_minmax_len(self, value, min_len, max_len, expected):
if expected is None:
validate_filename(value, min_len=min_len, max_len=max_len)
assert is_valid_filename(value, min_len=min_len, max_len=max_len)
else:
with pytest.raises(expected):
validate_filename(value, min_len=min_len, max_len=max_len)
def test_normal_multibyte(self, value, replace_text, expected):
sanitized_name = sanitize_filename(value, replace_text)
assert sanitized_name == expected
validate_filename(sanitized_name)
assert is_valid_filename(sanitized_name)
def test_exception_win_invalid_char(self, value, platform):
with pytest.raises(ValidationError) as e:
validate_filename(value, platform=platform)
assert e.value.reason == ErrorReason.INVALID_CHARACTER
assert not is_valid_filename(value, platform=platform)
def test_exception_filepath(self, value, platform):
with pytest.raises(ValidationError) as e:
validate_filename(value, platform=platform)
assert e.value.reason in [ErrorReason.FOUND_ABS_PATH, ErrorReason.INVALID_CHARACTER]
assert not is_valid_filename(value, platform=platform)