Пример #1
0
    def testTransformsLambda(self):
        def my_callable(v):
            return True

        validator = Validator.of(my_callable)
        self.assertIsInstance(validator, LambdaValidator)
        self.assertTrue(validator.isValid("test"))
Пример #2
0
 def __init__(self, pm: PropertyManager, validators=None):
     self.pm = pm
     self.pm.wire(self._fireCallbacks)
     if validators is None:
         self.validators = {}
     else:
         self.validators = {k: Validator.of(v) for k, v in validators.items()}
     super().__init__()
Пример #3
0
 def __init__(self, pm: PropertyManager, validators=None):
     super().__init__(pm)
     if validators is None:
         self.validators = {}
     else:
         self.validators = {
             k: Validator.of(v)
             for k, v in validators.items()
         }
Пример #4
0
 def testReturnsValidator(self):
     validator = NumberValidator()
     self.assertIs(validator, Validator.of(validator))
Пример #5
0
 def testGetsValidatorByKey(self):
     validator = Validator.of("str")
     self.assertIsInstance(validator, StringValidator)
Пример #6
0
 def setValidator(self, key, validator):
     self.validators[key] = Validator.of(validator)