How to use the pathvalidate.ErrorReason 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_filepath.py View on Github external
            [r"C:\Users:a", "windows", ErrorReason.INVALID_CHARACTER],
        ],
    )
    def test_exception(self, value, platform, expected):
        with pytest.raises(ValidationError) as e:
            validate_filepath(value, platform=platform)
        assert e.value.reason == expected
        assert not is_valid_filepath(value, platform=platform)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            ["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)
            return
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            ["invalid_length", 200, ErrorReason.INVALID_LENGTH],
        ],
    )
    def test_normal_min_len(self, value, min_len, expected):
        if expected is None:
            validate_filepath(value, min_len=min_len)
            assert is_valid_filepath(value, min_len=min_len)
            return

        with pytest.raises(ValidationError) as e:
            validate_filepath(value, min_len=min_len)
        assert e.value.reason == expected
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            ["C:\\Users\\" + "a" * 1024, "windows", ErrorReason.INVALID_LENGTH],
            [r"C:\Users:a", "windows", ErrorReason.INVALID_CHARACTER],
        ],
    )
    def test_exception(self, value, platform, expected):
        with pytest.raises(ValidationError) as e:
            validate_filepath(value, platform=platform)
        assert e.value.reason == expected
        assert not is_valid_filepath(value, platform=platform)
github thombashi / pathvalidate / test / test_filename.py View on Github external
            ["invalid_length", 200, ErrorReason.INVALID_LENGTH],
        ],
    )
    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
github thombashi / pathvalidate / test / test_filename.py View on Github external
def test_exception_escape_err_msg(self, value, platform, expected):
        with pytest.raises(ValidationError) as e:
            print(platform, repr(value))
            validate_filename(value, platform=platform)

        assert e.value.reason == ErrorReason.INVALID_CHARACTER
        assert str(e.value) == (
            r"invalid char found: invalids=('\r'), value='asdf\rsdf', "
            "reason=INVALID_CHARACTER, target-platform=Windows"
github thombashi / pathvalidate / test / test_filepath.py View on Github external
            [r"C:\Users:a", "universal", ErrorReason.MALFORMED_ABS_PATH],
            ["C:\\Users\\" + "a" * 1024, "windows", ErrorReason.INVALID_LENGTH],
            [r"C:\Users:a", "windows", ErrorReason.INVALID_CHARACTER],
        ],
    )
    def test_exception(self, value, platform, expected):
        with pytest.raises(ValidationError) as e:
            validate_filepath(value, platform=platform)
        assert e.value.reason == expected
        assert not is_valid_filepath(value, platform=platform)
github thombashi / pytablewriter / pytablewriter / writer / _elasticsearch.py View on Github external
def table_name(self, value):
        from ..sanitizer import ElasticsearchIndexNameSanitizer
        from pathvalidate import ValidationError, ErrorReason

        try:
            self._table_name = ElasticsearchIndexNameSanitizer(value).sanitize(replacement_text="_")
        except ValidationError as e:
            if e.reason is ErrorReason.NULL_NAME:
                self._table_name = None
            else:
                raise