Exemple #1
0
    def testValidValues(self):
        """ Tests the behavior for values in the defined range. """

        # upper and lower boundary
        inRangeValidator = validators.IsInRange(self.minValue, self.maxValue)
        inRangeValidator(300)
        inRangeValidator(self.minValue)
        inRangeValidator(self.maxValue)

        # upper boundary
        inRangeValidator = validators.IsInRange(maxValue=self.maxValue)
        inRangeValidator(300)
        inRangeValidator(self.minValue)
        inRangeValidator(self.maxValue)

        # lower boundary
        inRangeValidator = validators.IsInRange(minValue=self.minValue)
        inRangeValidator(300)
        inRangeValidator(self.minValue)
        inRangeValidator(self.maxValue)

        # no boundary
        inRangeValidator = validators.IsInRange()
        inRangeValidator(300)
        inRangeValidator(self.minValue)
        inRangeValidator(self.maxValue)
    def __init__(self,
                 minimum=None,
                 maximum=None,
                 minDecimalPlaces=None,
                 maxDecimalPlaces=None,
                 options=None,
                 optionsMandatory=True):
        """
        @param minimum: Minimum value. 
        @type minimum: C{decimal.Decimal}
        @param maximum: Maximum value.
        @type maximum: C{decimal.Decimal}
        @param options: List of options the value has to be taken from.
        @type options: C{list} of C{decimal.Decimal}
        @param optionsMandatory: Indicates whether the the value must 
            be one of C{options} or not. Default: C{False}
        @type optionsMandatory: C{bool}
        """

        base_validators.AndValidator.__init__(self, list())
        self.validators.append(
            base_validators.AreTypesMatched([int, float, Decimal]))
        self.validators.append(base_validators.IsInRange(minimum, maximum))
        self.validators.append(
            base_validators.IsNumberOfDecimalPlacesInRange(
                minDecimalPlaces, maxDecimalPlaces))
        if not options is None:
            self.validators.append(
                base_validators.AreOptionsMatched(options, optionsMandatory))
Exemple #3
0
    def testInvalidValues(self):
        """ Tests the behavior for values outside the defined range. """

        # lower and upper boundary
        inRangeValidator = validators.IsInRange(self.minValue, self.maxValue)
        self.assertRaises(ValueError, inRangeValidator, self.maxValue + 1)
        self.assertRaises(ValueError, inRangeValidator, self.minValue - 1)
        self.assertRaises(ValueError, inRangeValidator, 30009)
        self.assertRaises(ValueError, inRangeValidator, -110)

        # upper boundary
        inRangeValidator = validators.IsInRange(maxValue=self.maxValue)
        self.assertRaises(ValueError, inRangeValidator, self.maxValue + 1)
        self.assertRaises(ValueError, inRangeValidator, 30009)

        # lower boundary
        inRangeValidator = validators.IsInRange(minValue=self.minValue)
        self.assertRaises(ValueError, inRangeValidator, self.minValue - 1)
        self.assertRaises(ValueError, inRangeValidator, -110)
    def __init__(self, minimum=None, maximum=None, itemValidators=None):
        """
        @param minimum: Minimum length of the list.
        @type minimum: C{int}
        @param maximum: Maximum length of the list.
        @type maximum: C{int}
        @param itemValidators: List of checks for single items.
                               All checks are tried until at least one succeeds.
        @type itemValidators: C{list}
        """

        base_validators.AndValidator.__init__(self, list())
        self.validators.append(base_validators.AreTypesMatched([list]))
        self.validators.append(base_validators.IsInRange(minimum, maximum))
        if not itemValidators is None:
            self.validators.append(
                base_validators.ForEach(
                    base_validators.OrValidator(itemValidators)))
    def __init__(self,
                 minimum=None,
                 maximum=None,
                 options=None,
                 optionsMandatory=True):
        """
        @param minimum: Minimum length of the list.
        @type minimum: C{int}
        @param maximum: Maximum length of the list.
        @type maximum: C{int}
        @param options: List of options the value has to be taken from.
        @type options: C{list} of C{datetime}
        @param optionsMandatory: Indicates whether the the value must 
            be one of C{options} or not. Default: C{False}
        @type optionsMandatory: C{bool}
        """

        base_validators.AndValidator.__init__(self, list())
        self.validators.append(base_validators.AreTypesMatched([datetime]))
        self.validators.append(base_validators.IsInRange(minimum, maximum))
        if not options is None:
            self.validators.append(
                base_validators.AreOptionsMatched(options, optionsMandatory))