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(self, value, platform):
validate_filepath(value, platform)
assert is_valid_filepath(value, platform=platform)
def test_normal_path_separator(self, platform, value, expected):
sanitized = sanitize_filepath(value, platform=platform)
assert sanitized == expected
assert is_valid_filepath(sanitized, platform=platform)
def test_exception_type(self, value, expected):
with pytest.raises(expected):
sanitize_filepath(value)
assert not is_valid_filepath(value)
def test_normal_space_or_period_at_tail(self, platform, value):
validate_filepath(value, platform=platform)
assert is_valid_filepath(value, platform=platform)
def test_normal_max_len(self, value, platform, max_len, expected):
if expected is None:
validate_filepath(value, platform=platform, max_len=max_len)
assert is_valid_filepath(value, platform=platform, max_len=max_len)
return
with pytest.raises(ValidationError) as e:
validate_filepath(value, platform=platform, max_len=max_len)
assert e.value.reason == ErrorReason.INVALID_LENGTH
def test_normal_reserved_name_used_valid_place(self, value, platform):
validate_filepath(value, platform=platform)
assert is_valid_filepath(value, platform=platform)
def test_normal_auto_platform_linux(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 test_locale_jp(self, locale):
from faker import Factory
fake = Factory.create(locale=locale, seed=1)
for _ in range(100):
filepath = fake.file_path()
validate_filepath(filepath, platform="linux")
assert is_valid_filepath(filepath, platform="linux")
def test_normal_null_values(self, value, expected):
assert sanitize_filename(value) == expected
def test_normal_max_len(self, value, max_len, expected):
filename = sanitize_filename(value, max_len=max_len)
assert len(filename) == expected
assert is_valid_filename(filename, max_len=max_len)