Skip to content

Validation Module

Validation of configuration.

validate_config(config: dict, schema: Schema, config_type: str) -> None

Validate configuration.

Parameters:

Name Type Description Default
config dict

Config dictionary imported by read_yaml() and parsed through clean_config().

required
schema Schema

A schema against which the configuration is to be compared.

required
config_type str

Description of of configuration being validated.

required
Source code in topostats\validation.py
def validate_config(config: dict, schema: Schema, config_type: str) -> None:
    """
    Validate configuration.

    Parameters
    ----------
    config : dict
        Config dictionary imported by read_yaml() and parsed through clean_config().
    schema : Schema
        A schema against which the configuration is to be compared.
    config_type : str
        Description of of configuration being validated.
    """
    try:
        schema.validate(config)
        LOGGER.info(f"The {config_type} is valid.")
    except SchemaError as schema_error:
        raise SchemaError(
            f"There is an error in your {config_type} configuration. "
            "Please refer to the first error message above for details"
        ) from schema_error