File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -455,6 +455,35 @@ def property_values_string_check(prop):
455455Validation .register_handler ('property' , property_values_string_check )
456456
457457
458+ def section_properties_cardinality (obj ):
459+ """
460+ Checks Section properties against any set property cardinality.
461+
462+ :param obj: odml.Section
463+ :return: Yields a ValidationError warning, if a set cardinality is not met.
464+ """
465+ if obj .prop_cardinality and isinstance (obj .prop_cardinality , tuple ):
466+
467+ val_min = obj .prop_cardinality [0 ]
468+ val_max = obj .prop_cardinality [1 ]
469+
470+ val_len = len (obj .properties ) if obj .properties else 0
471+
472+ invalid_cause = ""
473+ if val_min and val_len < val_min :
474+ invalid_cause = "minimum %s" % val_min
475+ elif val_max and (obj .properties and len (obj .properties ) > val_max ):
476+ invalid_cause = "maximum %s" % val_max
477+
478+ if invalid_cause :
479+ msg = "Section properties cardinality violated"
480+ msg += " (%s values, %s found)" % (invalid_cause , val_len )
481+ yield ValidationError (obj , msg , LABEL_WARNING )
482+
483+
484+ Validation .register_handler ("section" , section_properties_cardinality )
485+
486+
458487def property_values_cardinality (prop ):
459488 """
460489 Checks Property values against any set value cardinality.
You can’t perform that action at this time.
0 commit comments