Skip to content

Commit d3faa1f

Browse files
committed
[test_validation.py] Change Error Assertion for Load Section Tests
For xml, json and yaml.
1 parent 6951184 commit d3faa1f

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

test/test_validation.py

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,12 @@ def test_load_section_xml(self):
240240
path = os.path.join(self.dir_path, "resources", "validation_section.xml")
241241
doc = odml.load(path)
242242

243-
sec_type_undefined_err = False
244-
sec_type_empty_err = False
245-
246-
for err in validate(doc).errors:
247-
if err.msg == "Section type undefined" and err.obj.name == "sec_type_undefined":
248-
sec_type_undefined_err = True
249-
elif err.msg == "Section type undefined" and err.obj.name == "sec_type_empty":
250-
sec_type_empty_err = True
251-
252-
assert sec_type_undefined_err
253-
assert sec_type_empty_err
243+
assert len(list(filter(
244+
lambda x: x.msg == "Section type undefined" and x.obj.name == "sec_type_undefined",
245+
validate(doc).errors))) > 0
246+
assert len(list(filter(
247+
lambda x: x.msg == "Section type undefined" and x.obj.name == "sec_type_empty",
248+
validate(doc).errors))) > 0
254249

255250
def test_load_dtypes_xml(self):
256251
"""
@@ -319,17 +314,12 @@ def test_load_section_json(self):
319314
path = os.path.join(self.dir_path, "resources", "validation_section.json")
320315
doc = odml.load(path, "JSON")
321316

322-
sec_type_undefined_err = False
323-
sec_type_empty_err = False
324-
325-
for err in validate(doc).errors:
326-
if err.msg == "Section type undefined" and err.obj.name == "sec_type_undefined":
327-
sec_type_undefined_err = True
328-
elif err.msg == "Section type undefined" and err.obj.name == "sec_type_empty":
329-
sec_type_empty_err = True
330-
331-
assert sec_type_undefined_err
332-
assert sec_type_empty_err
317+
assert len(list(filter(
318+
lambda x: x.msg == "Section type undefined" and x.obj.name == "sec_type_undefined",
319+
validate(doc).errors))) > 0
320+
assert len(list(filter(
321+
lambda x: x.msg == "Section type undefined" and x.obj.name == "sec_type_empty",
322+
validate(doc).errors))) > 0
333323

334324
def test_load_dtypes_json(self):
335325
"""
@@ -398,17 +388,12 @@ def test_load_section_yaml(self):
398388
path = os.path.join(self.dir_path, "resources", "validation_section.yaml")
399389
doc = odml.load(path, "YAML")
400390

401-
sec_type_undefined_err = False
402-
sec_type_empty_err = False
403-
404-
for err in validate(doc).errors:
405-
if err.msg == "Section type undefined" and err.obj.name == "sec_type_undefined":
406-
sec_type_undefined_err = True
407-
elif err.msg == "Section type undefined" and err.obj.name == "sec_type_empty":
408-
sec_type_empty_err = True
409-
410-
assert sec_type_undefined_err
411-
assert sec_type_empty_err
391+
assert len(list(filter(
392+
lambda x: x.msg == "Section type undefined" and x.obj.name == "sec_type_undefined",
393+
validate(doc).errors))) > 0
394+
assert len(list(filter(
395+
lambda x: x.msg == "Section type undefined" and x.obj.name == "sec_type_empty",
396+
validate(doc).errors))) > 0
412397

413398
def test_load_dtypes_yaml(self):
414399
"""

0 commit comments

Comments
 (0)