File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -484,6 +484,35 @@ def section_properties_cardinality(obj):
484484Validation .register_handler ("section" , section_properties_cardinality )
485485
486486
487+ def section_sections_cardinality (obj ):
488+ """
489+ Checks Section sub-sections against any set sub-section cardinality.
490+
491+ :param obj: odml.Section
492+ :return: Yields a ValidationError warning, if a set cardinality is not met.
493+ """
494+ if obj .sec_cardinality and isinstance (obj .sec_cardinality , tuple ):
495+
496+ val_min = obj .sec_cardinality [0 ]
497+ val_max = obj .sec_cardinality [1 ]
498+
499+ val_len = len (obj .sections ) if obj .sections else 0
500+
501+ invalid_cause = ""
502+ if val_min and val_len < val_min :
503+ invalid_cause = "minimum %s" % val_min
504+ elif val_max and (obj .sections and len (obj .sections ) > val_max ):
505+ invalid_cause = "maximum %s" % val_max
506+
507+ if invalid_cause :
508+ msg = "Section sub-section cardinality violated"
509+ msg += " (%s values, %s found)" % (invalid_cause , val_len )
510+ yield ValidationError (obj , msg , LABEL_WARNING )
511+
512+
513+ Validation .register_handler ("section" , section_sections_cardinality )
514+
515+
487516def property_values_cardinality (prop ):
488517 """
489518 Checks Property values against any set value cardinality.
You can’t perform that action at this time.
0 commit comments