sec_interp.core.validation.validation_helpers module
- class sec_interp.core.validation.validation_helpers.DependencyRule(condition: Callable[[], bool], check: Callable[[], bool], error_message: str, target_field: str | None = None)[source]
Bases:
objectRule defining a dependency between fields.
Example
If layer_selected is True, then field_name must be set.
- check: Callable[[], bool]
- condition: Callable[[], bool]
- error_message: str
- target_field: str | None = None
- validate(context: ValidationContext)[source]
Evaluate the rule and add error to context if failed.
- class sec_interp.core.validation.validation_helpers.RichValidationError(message: str, field_name: str | None = None, severity: str = 'error', context: dict[str, ~typing.Any]=<factory>)[source]
Bases:
objectA validation error with context details.
- context: dict[str, Any]
- field_name: str | None = None
- message: str
- severity: str = 'error'
- class sec_interp.core.validation.validation_helpers.ValidationContext[source]
Bases:
objectAccumulates validation results instead of failing fast.
Allows implementing a strategy where we collect all business logic errors before presenting them to the user.
- add_error(message: str, field_name: str | None = None, **kwargs)[source]
Add a hard error to the context.
- add_warning(message: str, field_name: str | None = None, **kwargs)[source]
Add a warning (soft error) to the context.
- property errors: list[RichValidationError]
Get list of accumulated errors.
- property has_errors: bool
Check if any hard errors exist.
- property has_warnings: bool
Check if any warnings exist.
- merge(other: ValidationContext)[source]
Merge another context into this one.
- property warnings: list[RichValidationError]
Get list of accumulated warnings.
- sec_interp.core.validation.validation_helpers.validate_dependencies(rules: list[DependencyRule], context: ValidationContext)[source]
Batch validate a list of dependency rules.
- sec_interp.core.validation.validation_helpers.validate_reasonable_ranges(values: dict[str, Any]) list[str][source]
Check for unreasonable or potentially erroneous parameter values.
This function does not return hard errors, but a list of warning strings to inform the user about extreme values (e.g., vertical exaggeration > 10).
- Parameters:
values – Dictionary containing parameter names and their current values.
- Returns:
A list of warning messages. If empty, all values are reasonable.