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.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/tutorius/constraints.py b/tutorius/constraints.py
index 36abdfb..455ede3 100644
--- a/tutorius/constraints.py
+++ b/tutorius/constraints.py
@@ -204,4 +204,22 @@ class FileConstraint(Constraint):
if not os.path.isfile(value):
raise FileConstraintError("Non-existing file : %s"%value)
return
-
+
+
+class SameTypeConstraintError(Exception):
+ pass
+
+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
+
+