How to use the pathvalidate.Platform function in pathvalidate

To help you get started, we’ve selected a few pathvalidate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pathvalidate / test / test_filename.py View on Github external
            ["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
github thombashi / pathvalidate / test / test_filename.py View on Github external
        [["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
github thombashi / pathvalidate / test / test_filepath.py View on Github external
        [["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
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            ["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
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            ["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)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            ["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