예제 #1
0
파일: dsl.py 프로젝트: dylandoamaral/certum
    def foreach(self, *args) -> DictRuleForeach:
        """Check if the current path respect a list of rules for each elements.

        :return: The DictRule related with this rule.
        :rtype: DictRuleForeach
        """
        rules = args_to_rule_decipher(*args)
        return DictRuleForeach(self.path, rules)
예제 #2
0
    def respects(self, *args) -> "DictValidator":
        """Provide a bunch of rules that need to be respected by the self.dictionary
        dictionary. These rules can be provided using
        :class:`certum.rule.generic.abstract.DictRule` or lists of
        :class:`certum.rule.generic.abstract.DictRule`.

        :raises CertumException: if one argument is not a DictRule complient
                                 argument.
        :return: Itself.
        :rtype: DictValidator
        """
        rules = args_to_rule_decipher(*args)
        return DictValidator(
            self.dictionary,
            self.rules + rules,
            self.sorting,
            self.filtering,
            self.printing,
        )
예제 #3
0
파일: dsl.py 프로젝트: dylandoamaral/certum
    def forsome(self, *args, **kwargs) -> DictRuleForsome:
        """Check if the current path respect a list of rules for elements corresponding
        to some keys.

        .. note::

            Forsome needs a parameter 'keys' that contains the keys to analyse.

        :return: The DictRule related with this rule.
        :rtype: DictRuleForsome
        """
        try:
            keys = kwargs["keys"]
            if not isinstance(keys, list):
                raise CertumException("Forsome needs a 'keys' argument of type list")
        except KeyError as error:
            raise CertumException(
                "Forsome needs a 'keys' argument of type list"
            ) from error
        rules = args_to_rule_decipher(*args)
        return DictRuleForsome(self.path, keys, rules)
예제 #4
0
def test_sucess():
    """Ensure that the decipher function can extract rules from arguments."""
    rules = args_to_rule_decipher(this.equals(2), this.has_unique_elements())
    assert len(rules) == 2
예제 #5
0
def test_failure_not_rule_in_list():
    """Ensure that the decipher should not extract argument inside a list that
    are not rules and raise a :class:`certum.exception.CertumException`."""
    with pytest.raises(CertumException):
        args_to_rule_decipher(["a"])