@@ -57,7 +57,7 @@ def test_property_values_cardinality(self):
57
57
for err in validate (doc ).errors :
58
58
self .assertNotEqual (err .obj .id , prop .id )
59
59
60
- # Test minimum value cardinality validation
60
+ # Test maximum value cardinality validation
61
61
test_val = [1 , 2 , 3 ]
62
62
test_card = 2
63
63
@@ -71,7 +71,7 @@ def test_property_values_cardinality(self):
71
71
self .assertFalse (err .is_error )
72
72
self .assertIn (test_msg , err .msg )
73
73
74
- # Test maximum value cardinality validation
74
+ # Test minimum value cardinality validation
75
75
test_val = "I am a nice text to test"
76
76
test_card = (4 , None )
77
77
@@ -84,6 +84,62 @@ def test_property_values_cardinality(self):
84
84
self .assertFalse (err .is_error )
85
85
self .assertIn (test_msg , err .msg )
86
86
87
+ def test_section_properties_cardinality (self ):
88
+ msg_base = "Section properties cardinality violated"
89
+
90
+ doc = odml .Document ()
91
+ # Test no caught warning on empty cardinality
92
+ sec = odml .Section (name = "prop_empty_cardinality" , type = "test" , parent = doc )
93
+ # Check that the current section did not throw any properties cardinality warnings
94
+ for err in validate (doc ).errors :
95
+ if err .obj .id == sec .id :
96
+ self .assertNotIn (msg_base , err .msg )
97
+
98
+ # Test no warning on valid cardinality
99
+ sec = odml .Section (name = "prop_valid_cardinality" , prop_cardinality = (1 , 2 ), parent = doc )
100
+ _ = odml .Property (parent = sec )
101
+ for err in validate (doc ).errors :
102
+ if err .obj .id == sec .id :
103
+ self .assertNotIn (msg_base , err .msg )
104
+
105
+ # Test maximum value cardinality validation
106
+ test_range = 3
107
+ test_card = 2
108
+ sec = odml .Section (name = "prop_invalid_max_val" , prop_cardinality = test_card , parent = doc )
109
+ for _ in range (test_range ):
110
+ _ = odml .Property (parent = sec )
111
+
112
+ test_msg = "%s (maximum %s values, %s found)" % (msg_base , test_card , len (sec .properties ))
113
+
114
+ # Once ValidationErrors provide validation ids, the following can be simplified.
115
+ found = False
116
+ for err in validate (doc ).errors :
117
+ if err .obj .id == sec .id and msg_base in err .msg :
118
+ self .assertFalse (err .is_error )
119
+ self .assertIn (test_msg , err .msg )
120
+ found = True
121
+
122
+ self .assertTrue (found )
123
+
124
+ # Test minimum value cardinality validation
125
+ test_card = (4 , None )
126
+
127
+ sec = odml .Section (name = "prop_invalid_min_val" , prop_cardinality = test_card , parent = sec )
128
+ _ = odml .Property (parent = sec )
129
+
130
+ test_msg = "%s (minimum %s values, %s found)" % (msg_base , test_card [0 ],
131
+ len (sec .properties ))
132
+
133
+ # Once ValidationErrors provide validation ids, the following can be simplified.
134
+ found = False
135
+ for err in validate (doc ).errors :
136
+ if err .obj .id == sec .id and msg_base in err .msg :
137
+ self .assertFalse (err .is_error )
138
+ self .assertIn (test_msg , err .msg )
139
+ found = True
140
+
141
+ self .assertTrue (found )
142
+
87
143
def test_section_in_terminology (self ):
88
144
doc = samplefile .parse ("""s1[T1]""" )
89
145
res = validate (doc )
0 commit comments