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.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/tutorius/constraints.py b/tutorius/constraints.py
index f2e324f..455ede3 100644
--- a/tutorius/constraints.py
+++ b/tutorius/constraints.py
@@ -205,13 +205,21 @@ class FileConstraint(Constraint):
raise FileConstraintError("Non-existing file : %s"%value)
return
-class SameTypeConstraint(Exception):
+
+class SameTypeConstraintError(Exception):
pass
-class SameTypeConstraint(ValueConstraint):
- pass
- #def validate(self, typePropertie):
- # if self.limit != typePropertie:
- # raise SameTypeConstraint("Value with a diffferent type")
- #return
+class SameTypeConstraint(Constraint):
+ """
+ Ensures that the list is not empty and that properties of the list have the same type.
+ """
+
+ def validate(self, value):
+ if len(value)==0:
+ raise SameTypeConstraintError("The list is empty")
+ for i in value:
+ if i.type != value[0].type:
+ raise SameTypeConstraintError("Properties have diffferent type")
+ return
+