Beispiel #1
0
    def is_valid(self, raise_exception=True) -> bool:
        """ Performs static checks on ``self`` to ensure it is a valid Scenario object."""

        req_keys = ["name", "models", "input_conf", "output_conf"]

        if not all([k in self.keys() for k in req_keys]):
            raise TypeError(
                ("Not all required key-value pairs have been defined. " +
                 "It is necessary to define all of %s.") % req_keys)

        if not isinstance(self["models"], list):
            raise TypeError(
                "Scenario property \'models\' must be defined as a list.")

        for model in self["models"]:
            if not issubclass(type(model), Model):
                raise TypeError("Object '%s' is of type '%s', not 'Model'." %
                                (model, type(model)))

            if not model.check_config(raise_exception=raise_exception,
                                      runtime=False):
                return False

        for ic in self["input_conf"]:
            if not ToCERO.check_config(
                    ic, raise_exception=raise_exception, runtime=False):
                return False

        for oc in self["output_conf"]:
            if not FromCERO.check_config(
                    oc, raise_exception=raise_exception, runtime=False):
                return False

        return True
Beispiel #2
0
    def is_valid(self, raise_exception=True):
        """
        Checks the validity of ``self`` as a ``Model`` object. Method does not ensure runtime issues will not occur.
        :param bool raise_exception:
        :return bool: Returns `True` if ``self`` is a valid ``Model``.
        """
        req_keys = ["name", "cmds", "input_conf", "output_conf"]

        if not all([k in self for k in req_keys]):

            msg = (
                "All models must have all of the keys: %s. Attempted to create model"
                + " with at least one of these keys missing.") % req_keys

            Model._logger.error(msg)
            if raise_exception:
                raise TypeError(msg)
            print(msg)
            return False

        for ic in self["input_conf"]:
            if not FromCERO.check_config(
                    ic, raise_exception=raise_exception, runtime=False):
                return False

        for oc in self["output_conf"]:
            if not ToCERO.check_config(
                    oc, raise_exception=raise_exception, runtime=False):
                return False

        return True
Beispiel #3
0
    def run_checks(self, raise_exception=True):
        """
        Performs runtime checks on ``self`` to ensure it is a valid Scenario object. Failure of runtime checks indicates that the scenario is not ready to run.

        :param bool raise_exception: If `True` (default) then an exception is raised on check failure. Otherwise (on check failure) `False` is returned.
        :return:
        """

        for ic in self["input_conf"]:
            if not ToCERO.check_config(
                    ic, raise_exception=raise_exception, runtime=True):
                return False
        return True