Source code for cosapp.drivers.validitycheck

import logging

from cosapp.drivers.optionaldriver import OptionalDriver
from cosapp.utils.validate import validate

logger = logging.getLogger(__name__)


# TODO
# [ ] Quid for vector variables
[docs] class ValidityCheck(OptionalDriver): """ When executed, this driver reports in the log the validity status for all variables of the driver `System` owner (and its children). Parameters ---------- name : str Name of the driver owner : System :py:class:`~cosapp.systems.system.System` to which this driver belong **kwargs : Any Keyword arguments will be used to set driver options """ __slots__ = tuple()
[docs] def compute(self) -> None: """Report in the log the validity status for all variables recursively collected in owner `System` and its children. """ warnings, errors = validate(self.owner) def messages(log_dict): return list(f"{key}{msg}" for key, msg in log_dict.items()) separator = "\n- " if errors: error_msg = separator.join(["Errors:"] + messages(errors)) logger.error(error_msg) if warnings: warning_msg = separator.join(["Warnings:"] + messages(warnings)) if errors: warning_msg = f"\n{warning_msg}" logger.warning(warning_msg)