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")
dirnames, unmatched = photo.render_template(directory)
if not dirnames:
raise click.BadOptionUsage(
"directory",
f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}",
)
elif unmatched:
raise click.BadOptionUsage(
"directory",
f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}",
)
dest_paths = []
for dirname in dirnames:
dirname = sanitize_filepath(dirname, platform="auto")
dest_path = os.path.join(dest, dirname)
if not is_valid_filepath(dest_path, platform="auto"):
raise ValueError(f"Invalid file path: '{dest_path}'")
if not dry_run and not os.path.isdir(dest_path):
os.makedirs(dest_path)
dest_paths.append(dest_path)
else:
dest_paths = [dest]
return dest_paths