input4mips_validation.validation.error_catching#
input4mips_validation.validation.error_catching
#
Tools for catching errors in validation without stopping
ValidationResult
#
The result of a validation operation
This is basically a result class, similar to what is often used in railway oriented programming.
Source code in src/input4mips_validation/validation/error_catching.py
description: str
instance-attribute
#
Description of the validation operation
exception: Union[Exception, None] = field(default=None, validator=exception_info_consistent_with_passed)
class-attribute
instance-attribute
#
If the validation failed, the exception that was raised.
exception_info: Union[str, None] = field(default=None, validator=exception_info_consistent_with_passed)
class-attribute
instance-attribute
#
If the validation failed, the exception information.
This is typically created with traceback.format_exc.
failed: bool
property
#
Whether the validation failed or not
passed: bool
instance-attribute
#
Whether the validation passed or not
result: Any = field(default=None)
class-attribute
instance-attribute
#
If the validation passed, the result of the function that was called.
ValidationResultsStore
#
Store for validation results
Source code in src/input4mips_validation/validation/error_catching.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
all_passed: bool
property
#
Whether all the validation steps passed or not
checks_failing: tuple[ValidationResult, ...]
property
#
Checks that failed
checks_passing: tuple[ValidationResult, ...]
property
#
Checks that passed
validation_results: list[ValidationResult] = field(factory=list)
class-attribute
instance-attribute
#
Stored validation results
checks_summary_str(passing)
#
Get a summary of the checks we have performed
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
passing
|
bool
|
Should we return the summary as the number of checks
which are passing ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
Summary of the checks |
Source code in src/input4mips_validation/validation/error_catching.py
raise_if_errors()
#
Raise a ValidationError if any of the validation steps failed
Raises:
| Type | Description |
|---|---|
ValidationError
|
One of the validation steps in |
Source code in src/input4mips_validation/validation/error_catching.py
wrap(func_to_call, func_description)
#
Wrap a validation function
The results of calling the validation function will be stored by self.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func_to_call
|
Callable[P, T]
|
Function to call |
required |
func_description
|
str
|
A description of This helps us create clearer messages when processing validation results. |
required |
Returns:
| Type | Description |
|---|---|
Callable[P, ValidationResult]
|
The wrapped function. The wrapped function is altered so it always returns a result,
irrespective of whether |
Source code in src/input4mips_validation/validation/error_catching.py
ValidationResultsStoreError
#
Bases: ValueError
Raised to signal that an error occured during validation
Specifically, that a
ValidationResultsStore
object contains failed validation results.
Source code in src/input4mips_validation/validation/error_catching.py
__init__(vrs)
#
Initialise the error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vrs
|
ValidationResultsStore
|
The validation results store that contains failures. |
required |
Source code in src/input4mips_validation/validation/error_catching.py
exception_info_consistent_with_passed(instance, attribute, value)
#
Check the exception information is consistent with the passed status
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
ValidationResult
|
Instance to check |
required |
attribute
|
Attribute[Any]
|
Attribute being set |
required |
value
|
Union[Any, None]
|
Value being set |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
|