Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
["valid_length", Platform.UNIVERSAL, 255, None],
["invalid_length", None, 2, ErrorReason.INVALID_LENGTH],
],
)
def test_max_len(self, value, platform, max_len, expected):
if expected is None:
validate_filename(value, platform=platform, max_len=max_len)
assert is_valid_filename(value, platform=platform, max_len=max_len)
return
with pytest.raises(ValidationError) as e:
validate_filename(value, platform=platform, max_len=max_len)
assert e.value.reason == expected
[["windows", Platform.WINDOWS], ["linux", Platform.LINUX], ["macos", Platform.MACOS]],
)
def test_normal_platform_auto(self, monkeypatch, test_platform, expected):
if test_platform == "windows":
patch = lambda: "windows"
elif test_platform == "linux":
patch = lambda: "linux"
elif test_platform == "macos":
patch = lambda: "macos"
else:
raise ValueError("unexpected test platform: {}".format(test_platform))
monkeypatch.setattr(m_platform, "system", patch)
assert FileNameSanitizer(255, platform="auto").platform == expected
[["windows", Platform.WINDOWS], ["linux", Platform.LINUX], ["macos", Platform.MACOS]],
)
def test_normal_platform_auto(self, monkeypatch, test_platform, expected):
if test_platform == "windows":
patch = lambda: "windows"
elif test_platform == "linux":
patch = lambda: "linux"
elif test_platform == "macos":
patch = lambda: "macos"
else:
raise ValueError("unexpected test platform: {}".format(test_platform))
monkeypatch.setattr(m_platform, "system", patch)
assert FilePathSanitizer(255, platform="auto").platform == expected
["a" * 261, Platform.UNIVERSAL, None, ErrorReason.INVALID_LENGTH],
],
)
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
["a" * 4097, Platform.LINUX, None, ErrorReason.INVALID_LENGTH],
["a" * 255, "linux", 100, ErrorReason.INVALID_LENGTH],
["a" * 5000, "windows", 10000, ErrorReason.INVALID_LENGTH],
["a" * 260, "windows", None, None],
["a" * 300, "windows", 1024, ErrorReason.INVALID_LENGTH],
["a" * 261, Platform.WINDOWS, None, ErrorReason.INVALID_LENGTH],
["a" * 261, "windows", None, ErrorReason.INVALID_LENGTH],
["a" * 260, "universal", None, None],
["a" * 261, "universal", None, ErrorReason.INVALID_LENGTH],
["a" * 300, "universal", 1024, ErrorReason.INVALID_LENGTH],
["a" * 261, Platform.UNIVERSAL, None, ErrorReason.INVALID_LENGTH],
],
)
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)
["a" * 261, Platform.WINDOWS, None, ErrorReason.INVALID_LENGTH],
["a" * 261, "windows", None, ErrorReason.INVALID_LENGTH],
["a" * 260, "universal", None, None],
["a" * 261, "universal", None, ErrorReason.INVALID_LENGTH],
["a" * 300, "universal", 1024, ErrorReason.INVALID_LENGTH],
["a" * 261, Platform.UNIVERSAL, None, ErrorReason.INVALID_LENGTH],
],
)
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