sec_interp.core.validation.validation_helpers module

Helper classes and functions for Level 2 (Business Validation).

This module provides tools for: - Accumulating validation errors (ValidationContext) - Handling structured errors (RichValidationError) - Defining and checking dependency rules between fields/layers.

class sec_interp.core.validation.validation_helpers.DependencyRule(condition: Callable[[], bool], check: Callable[[], bool], error_message: str, target_field: str | None = None)

Bases: object

Rule 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) None

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>)

Bases: object

A validation error with context details.

__str__() str

Return a string representation of the error.

context: dict[str, Any]
field_name: str | None = None
message: str
severity: str = 'error'
class sec_interp.core.validation.validation_helpers.ValidationContext

Bases: object

Accumulates validation results instead of failing fast.

Allows implementing a strategy where we collect all business logic errors before presenting them to the user.

__init__() None

Initialize the validation results collector.

add_error(message: str, field_name: str | None = None, **kwargs) None

Add a hard error to the context.

add_warning(message: str, field_name: str | None = None, **kwargs) None

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) None

Merge another context into this one.

raise_if_errors() None

Raise ValidationError if any errors exist.

property warnings: list[RichValidationError]

Get list of accumulated warnings.

sec_interp.core.validation.validation_helpers.validate_dependencies(rules: list[DependencyRule], context: ValidationContext) None

Batch validate a list of dependency rules.

sec_interp.core.validation.validation_helpers.validate_reasonable_ranges(values: dict[str, Any]) list[str]

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.