Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/constraints.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/constraints.py')
-rw-r--r--tutorius/constraints.py35
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
+
+