Coverage for src / ezcompiler / utils / validators / meta_validators.py: 27.78%
12 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 06:49 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 06:49 +0000
1# ///////////////////////////////////////////////////////////////
2# META_VALIDATORS - Meta validation utilities
3# Project: ezcompiler
4# ///////////////////////////////////////////////////////////////
6"""
7Meta validators - Validation utilities for batch validation operations.
9This module provides validation functions for performing multiple validations
10at once using a declarative approach.
11"""
13from __future__ import annotations
15# ///////////////////////////////////////////////////////////////
16# IMPORTS
17# ///////////////////////////////////////////////////////////////
18# Standard library imports
19from collections.abc import Callable
20from typing import Any
22# Local imports
23from ...shared.exceptions.utils.validation_exceptions import SchemaValidationError
25# ///////////////////////////////////////////////////////////////
26# FUNCTIONS
27# ///////////////////////////////////////////////////////////////
30def validate_multiple(
31 validations: list[tuple[Any, str, str]],
32 validators: dict[str, Callable],
33) -> None:
34 """
35 Perform multiple validations at once.
37 Args:
38 validations: List of (value, validator_name, field_name) tuples
39 validators: Dict of validator_name -> validator_function
41 Raises:
42 SchemaValidationError: If any validation fails
44 Example:
45 >>> validations = [
46 ... ("1.0.0", "version_string", "version"),
47 ... ("user@example.com", "email", "contact_email"),
48 ... ("https://example.com", "url", "server_url"),
49 ... ]
50 >>> validators = {
51 ... "version_string": ValidationUtils.validate_version_string,
52 ... "email": ValidationUtils.validate_email,
53 ... "url": ValidationUtils.validate_url,
54 ... }
55 >>> validate_multiple(validations, validators)
57 Raises:
58 SchemaValidationError: If any validation fails
59 """
60 for value, validator_name, field_name in validations:
61 if validator_name not in validators:
62 raise SchemaValidationError(f"Unknown validator: {validator_name}")
64 validator = validators[validator_name]
65 result = validator(value)
66 if not result:
67 raise SchemaValidationError(f"Invalid {field_name}: {value}")