speedwagon.validators¶
Validation code.
This contains mainly code for validating input.
- class speedwagon.validators.AbsOutputValidation¶
- Generic abstract base class for user options validations. - If validate() is called or the “candidate” property is read prior to setting the candidate property, a ValueError will be thrown. - To subclass, implement the investigate() method. - __init__() None¶
- Create a new validation object with no results. 
 - property candidate: _T | None¶
- Get candidate. - If not set prior, this will raise a ValueError 
 - abstract investigate(candidate: _T | None, job_options: Dict[str, UserDataType]) List[ReportT]¶
- Test that returns any findings in the generic report format. - This needs to be implemented in any subclass. - Parameters:
- candidate – Anything that is being validated. 
- job_options – dictionary of the keys and values of other user arguments used by the job. 
 
- Returns:
- Returns a list of findings if any found, otherwise it returns an empty list. 
 
 - reset() None¶
- Reset any findings stored by the validation instance. 
 - validate(job_options: Dict[str, str | Any] | None = None) None¶
- Set is_valid and findings. 
 
- class speedwagon.validators.ExistsOnFileSystem(message_template='{} does not exist')¶
- Validate a file or folder exists on the file system. 
- class speedwagon.validators.IsDirectory(message_template='{} is not a directory')¶
- Validation for the string pointing to a directory. - __init__(message_template='{} is not a directory') None¶
- Create a new validation for string pointing to directory. - Parameters:
- message_template – Message template when candidate fails validation. Note: There is a single value in the template for the input value. 
 
 
- class speedwagon.validators.IsFile(message_template='{} is not a file')¶
- __init__(message_template='{} is not a file') None¶
- Create a new validation object with no results. 
 
- class speedwagon.validators.CustomValidation(query: Callable[[_T | None, Dict[str, str | Any]], bool], failure_message_function: Callable[[_T | None], str] | None = None)¶
- Allows for simple custom validation. - Examples - >>> validation = CustomValidation( ... query=lambda candidate, _: candidate.isalpha(), ... failure_message_function=lambda candidate:( ... f"{candidate} contains non-alphanumerical characters" ... ) ... ) >>> validation.investigate("s1", {}) ['s1 contains non-alphanumerical characters'] - __init__(query: Callable[[_T | None, Dict[str, str | Any]], bool], failure_message_function: Callable[[_T | None], str] | None = None) None¶
- Create a custom validation object. - Parameters:
- query – Callable function that validates the candidate and returns True or False based on the success of failure of the validation. 
- failure_message_function – Callable function that takes the failed candidate as an argument and returns a string to explain the validation failed. 
 
 
 
