ValidFile#
- class movement.validators.files.ValidFile(path, *, expected_permission='r', expected_suffix=NOTHING)[source]#
Bases:
object
Class for validating file paths.
The validator ensures that the file:
is not a directory,
exists if it is meant to be read,
does not exist if it is meant to be written,
has the expected access permission(s), and
has one of the expected suffix(es).
- path#
Path to the file.
- Type:
str or pathlib.Path
- expected_permission#
Expected access permission(s) for the file. If “r”, the file is expected to be readable. If “w”, the file is expected to be writable. If “rw”, the file is expected to be both readable and writable. Default: “r”.
- Type:
{“r”, “w”, “rw”}
- expected_suffix#
Expected suffix(es) for the file. If an empty list (default), this check is skipped.
- Type:
list of str
- Raises:
IsADirectoryError – If the path points to a directory.
PermissionError – If the file does not have the expected access permission(s).
FileNotFoundError – If the file does not exist when
expected_permission
is “r” or “rw”.FileExistsError – If the file exists when
expected_permission
is “w”.ValueError – If the file does not have one of the expected suffix(es).