diff options
author | isen <isen@isen-desktop.(none)> | 2009-10-18 11:42:01 (GMT) |
---|---|---|
committer | isen <isen@isen-desktop.(none)> | 2009-10-18 11:42:01 (GMT) |
commit | e9fd92d03bb176cdab9fc3956ecd8cebdc3cc085 (patch) | |
tree | 41e0a04647b396d517b02da36b0847d1dd56e41c /tutorius/constraints.py | |
parent | 04bef3e0d6f0db689b31c05799f9a6c55e3220d9 (diff) |
lp426452 Todo retour constraints fix after holiday
Diffstat (limited to 'tutorius/constraints.py')
-rw-r--r-- | tutorius/constraints.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/tutorius/constraints.py b/tutorius/constraints.py index e6c942f..cfe7b5f 100644 --- a/tutorius/constraints.py +++ b/tutorius/constraints.py @@ -247,31 +247,32 @@ class ListIntCheckConstraint(Constraint):####################################### for i in range(len(value)): int(value[i])#la fonction int() ne peut convertir que des nombres ou des string sinon error (ex pas de int([0,0])) except: - raise IntCheckConstraintError("The value can't be converted into an int") + raise IntCheckConstraintError("The value: '" + str(value) + "' can't be converted into an int") return -class TypeConstraint(Constraint):################################################################ - """ - A Type constraint contains a OneType member that can be used in a children - class as a basic string. ex : SameTypeConstraint - """ - def __init__(self, one_type): - self.one_type = one_type - class SameTypeConstraintError(Exception):######################################################## pass -class SameTypeConstraint(TypeConstraint):######################################################## +class SameTypeConstraint(Constraint):######################################################## """ Ensures that the list is not empty and that properties of the list have the same type. """ + def __init__(self, tutoProp): + if tutoProp is not None: + self.tutoProp = tutoProp + else: + raise Exception("Property must exist")#ToDo + def validate(self, value): - if self.one_type is not None: - if len(value)==0: - raise SameTypeConstraintError("The list is empty") - for i in value: - if type(i) != self.one_type: - raise SameTypeConstraintError("Properties have diffferent type") - return + if len(value)==0: + raise SameTypeConstraintError("The list is empty") + + for i in value: + self.tutoProp.validate(i) + #raise SameTypeConstraintError("Properties have diffferent type") + return value + #faire pour une collection qui fait appel a une contrainte type sur une valeur + + |