Skip to content

Commit ec375ab

Browse files
committed
[test/validation] Reduce section val redundancy
1 parent d00503d commit ec375ab

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

test/test_validation.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,19 @@ def test_prop_string_values(self):
287287
'(39.12; 56; 67.18)'])
288288
self.assertError(validate(prop9), msg_base % ("Coos", "3-tuple"))
289289

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+
290303
def test_load_section_xml(self):
291304
"""
292305
Test if loading xml document raises validation errors for Sections with undefined type.
@@ -295,12 +308,7 @@ def test_load_section_xml(self):
295308
path = os.path.join(self.dir_path, "resources", "validation_section.xml")
296309
doc = odml.load(path)
297310

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)
304312

305313
def test_load_section_json(self):
306314
"""
@@ -310,12 +318,7 @@ def test_load_section_json(self):
310318
path = os.path.join(self.dir_path, "resources", "validation_section.json")
311319
doc = odml.load(path, "JSON")
312320

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)
319322

320323
def test_load_section_yaml(self):
321324
"""
@@ -325,12 +328,7 @@ def test_load_section_yaml(self):
325328
path = os.path.join(self.dir_path, "resources", "validation_section.yaml")
326329
doc = odml.load(path, "YAML")
327330

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)
334332

335333
def load_dtypes_validation(self, doc):
336334
msg_base = 'Dtype of property "%s" currently is "string", but might fit dtype "%s"!'

0 commit comments

Comments
 (0)