@@ -1066,6 +1066,59 @@ def test_properties_cardinality(self):
1066
1066
# Use general method to reduce redundancy
1067
1067
self ._test_cardinality_re_assignment (sec , 'prop_cardinality' )
1068
1068
1069
+ def _test_set_cardinality_method (self , obj , obj_attribute , set_cardinality_method ):
1070
+ """
1071
+ Tests the basic set convenience method of both Section properties and
1072
+ sub-sections cardinality.
1073
+
1074
+ :param obj: odml Section
1075
+ :param obj_attribute: string with the cardinality attribute that is supposed to be tested.
1076
+ Should be either 'prop_cardinality' or 'sec_cardinality'.
1077
+ :param set_cardinality_method: The convenience method used to set the cardinality.
1078
+ """
1079
+ oba = obj_attribute
1080
+
1081
+ # Test Section prop/sec cardinality min assignment
1082
+ set_cardinality_method (1 )
1083
+ self .assertEqual (getattr (obj , oba ), (1 , None ))
1084
+
1085
+ # Test Section prop/sec cardinality keyword min assignment
1086
+ set_cardinality_method (min_val = 2 )
1087
+ self .assertEqual (getattr (obj , oba ), (2 , None ))
1088
+
1089
+ # Test Section prop/sec cardinality max assignment
1090
+ set_cardinality_method (None , 1 )
1091
+ self .assertEqual (getattr (obj , oba ), (None , 1 ))
1092
+
1093
+ # Test Section prop/sec cardinality keyword max assignment
1094
+ set_cardinality_method (max_val = 2 )
1095
+ self .assertEqual (getattr (obj , oba ), (None , 2 ))
1096
+
1097
+ # Test Section prop/sec cardinality min max assignment
1098
+ set_cardinality_method (1 , 2 )
1099
+ self .assertEqual (getattr (obj , oba ), (1 , 2 ))
1100
+
1101
+ # Test Section prop/sec cardinality keyword min max assignment
1102
+ set_cardinality_method (min_val = 2 , max_val = 5 )
1103
+ self .assertEqual (getattr (obj , oba ), (2 , 5 ))
1104
+
1105
+ # Test Section prop/sec cardinality empty reset
1106
+ set_cardinality_method ()
1107
+ self .assertIsNone (getattr (obj , oba ))
1108
+
1109
+ # Test Section prop/sec cardinality keyword empty reset
1110
+ set_cardinality_method (1 )
1111
+ self .assertIsNotNone (getattr (obj , oba ))
1112
+ set_cardinality_method (min_val = None , max_val = None )
1113
+ self .assertIsNone (getattr (obj , oba ))
1114
+
1115
+ def test_set_properties_cardinality (self ):
1116
+ doc = Document ()
1117
+ sec = Section (name = "sec" , type = "test" , parent = doc )
1118
+
1119
+ # Use general method to reduce redundancy
1120
+ self ._test_set_cardinality_method (sec , 'prop_cardinality' , sec .set_properties_cardinality )
1121
+
1069
1122
def test_link (self ):
1070
1123
pass
1071
1124
0 commit comments