How to use the pathvalidate.is_valid_filepath 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
def test_normal(self, value, platform):
        validate_filepath(value, platform)
        assert is_valid_filepath(value, platform=platform)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
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)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
def test_exception_type(self, value, expected):
        with pytest.raises(expected):
            sanitize_filepath(value)
        assert not is_valid_filepath(value)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
def test_normal_space_or_period_at_tail(self, platform, value):
        validate_filepath(value, platform=platform)
        assert is_valid_filepath(value, platform=platform)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
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
def test_normal_reserved_name_used_valid_place(self, value, platform):
        validate_filepath(value, platform=platform)
        assert is_valid_filepath(value, platform=platform)
github thombashi / pathvalidate / test / test_filepath.py View on Github external
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")
github thombashi / pathvalidate / test / test_filepath.py View on Github external
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")
github RhetTbull / osxphotos / osxphotos / __main__.py View on Github external
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