@@ -57,7 +57,7 @@ def test_property_values_cardinality(self):
5757 for err in validate (doc ).errors :
5858 self .assertNotEqual (err .obj .id , prop .id )
5959
60- # Test minimum value cardinality validation
60+ # Test maximum value cardinality validation
6161 test_val = [1 , 2 , 3 ]
6262 test_card = 2
6363
@@ -71,7 +71,7 @@ def test_property_values_cardinality(self):
7171 self .assertFalse (err .is_error )
7272 self .assertIn (test_msg , err .msg )
7373
74- # Test maximum value cardinality validation
74+ # Test minimum value cardinality validation
7575 test_val = "I am a nice text to test"
7676 test_card = (4 , None )
7777
@@ -84,6 +84,62 @@ def test_property_values_cardinality(self):
8484 self .assertFalse (err .is_error )
8585 self .assertIn (test_msg , err .msg )
8686
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+
87143 def test_section_in_terminology (self ):
88144 doc = samplefile .parse ("""s1[T1]""" )
89145 res = validate (doc )
0 commit comments