@@ -287,6 +287,19 @@ def test_prop_string_values(self):
287
287
'(39.12; 56; 67.18)' ])
288
288
self .assertError (validate (prop9 ), msg_base % ("Coos" , "3-tuple" ))
289
289
290
+ def load_section_validation (self , doc ):
291
+ filter_func = lambda x : x .msg == filter_msg and x .obj .name == filter_name
292
+
293
+ # Check error for deliberate empty section type
294
+ filter_msg = "Missing required attribute 'type'"
295
+ filter_name = "sec_type_empty"
296
+ self .assertGreater (len (list (filter (filter_func , validate (doc ).errors ))), 0 )
297
+
298
+ # Check warning for not specified section type
299
+ filter_msg = "Section type not specified"
300
+ filter_name = "sec_type_undefined"
301
+ self .assertGreater (len (list (filter (filter_func , validate (doc ).errors ))), 0 )
302
+
290
303
def test_load_section_xml (self ):
291
304
"""
292
305
Test if loading xml document raises validation errors for Sections with undefined type.
@@ -295,12 +308,7 @@ def test_load_section_xml(self):
295
308
path = os .path .join (self .dir_path , "resources" , "validation_section.xml" )
296
309
doc = odml .load (path )
297
310
298
- assert len (list (filter (
299
- lambda x : x .msg == "Section type undefined" and x .obj .name == "sec_type_undefined" ,
300
- validate (doc ).errors ))) > 0
301
- assert len (list (filter (
302
- lambda x : x .msg == "Section type undefined" and x .obj .name == "sec_type_empty" ,
303
- validate (doc ).errors ))) > 0
311
+ self .load_section_validation (doc )
304
312
305
313
def test_load_section_json (self ):
306
314
"""
@@ -310,12 +318,7 @@ def test_load_section_json(self):
310
318
path = os .path .join (self .dir_path , "resources" , "validation_section.json" )
311
319
doc = odml .load (path , "JSON" )
312
320
313
- assert len (list (filter (
314
- lambda x : x .msg == "Section type undefined" and x .obj .name == "sec_type_undefined" ,
315
- validate (doc ).errors ))) > 0
316
- assert len (list (filter (
317
- lambda x : x .msg == "Section type undefined" and x .obj .name == "sec_type_empty" ,
318
- validate (doc ).errors ))) > 0
321
+ self .load_section_validation (doc )
319
322
320
323
def test_load_section_yaml (self ):
321
324
"""
@@ -325,12 +328,7 @@ def test_load_section_yaml(self):
325
328
path = os .path .join (self .dir_path , "resources" , "validation_section.yaml" )
326
329
doc = odml .load (path , "YAML" )
327
330
328
- assert len (list (filter (
329
- lambda x : x .msg == "Section type undefined" and x .obj .name == "sec_type_undefined" ,
330
- validate (doc ).errors ))) > 0
331
- assert len (list (filter (
332
- lambda x : x .msg == "Section type undefined" and x .obj .name == "sec_type_empty" ,
333
- validate (doc ).errors ))) > 0
331
+ self .load_section_validation (doc )
334
332
335
333
def load_dtypes_validation (self , doc ):
336
334
msg_base = 'Dtype of property "%s" currently is "string", but might fit dtype "%s"!'
0 commit comments