Skip to content

Commit 8a49b32

Browse files
committed
[property] Add validation on val_cardinality set
When setting a values cardinality and the current number of values violate the cardinality a warning is printed to the user.
1 parent e5a5ac7 commit 8a49b32

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

odml/property.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def __init__(self, name=None, values=None, parent=None, unit=None,
133133

134134
self.parent = parent
135135

136+
# Cardinality should always be set after values have been added
137+
# since it is always tested against values when it is set.
136138
self._val_cardinality = None
137139
self.val_cardinality = val_cardinality
138140

@@ -572,7 +574,12 @@ def val_cardinality(self, new_value):
572574
else:
573575
invalid_input = True
574576

575-
if invalid_input:
577+
if not invalid_input:
578+
# Validate and inform user if the current values cardinality is violated
579+
valid = validation.Validation(self)
580+
for err in valid.errors:
581+
print("%s: %s" % (err.rank.capitalize(), err.msg))
582+
else:
576583
msg = "Can only assign single int or int-tuples of the format '(min, max)'"
577584
raise ValueError(msg)
578585

0 commit comments

Comments
 (0)