Skip to content

Commit d1755a6

Browse files
committed
[test/parser_yaml] Add invalid attribute test
1 parent a0c4b08 commit d1755a6

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

test/test_parser_yaml.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,47 @@ def test_invalid_version(self):
7171

7272
with self.assertRaises(InvalidVersionException):
7373
_ = self.yaml_reader.to_odml(parsed_doc)
74+
75+
def test_invalid_attribute_handling(self):
76+
filename = "invalid_attributes.yaml"
77+
78+
inv_doc_attr = "invalid_doc_attr"
79+
inv_sec_attr = "invalid_sec_attr"
80+
inv_prop_attr = "invalid_prop_attr"
81+
82+
file_content = """Document:
83+
id: 82408bdb-1d9d-4fa9-b4dd-ad78831c797c
84+
%s: i_do_not_exist_on_doc_level
85+
sections:
86+
- id: d4f3120a-c02f-4102-a9fe-2e8b77d1d0d2
87+
name: sec
88+
%s: i_do_not_exist_on_sec_level
89+
properties:
90+
- id: 18ad5176-2b46-4a08-9b85-eafd6b14fab7
91+
name: prop
92+
value: []
93+
%s: i_do_not_exist_on_prop_level
94+
sections: []
95+
type: test
96+
odml-version: '1.1'
97+
""" % (inv_doc_attr, inv_sec_attr, inv_prop_attr)
98+
99+
parsed_doc = self._prepare_doc(filename, file_content)
100+
101+
# Test ParserException on default parse
102+
exc_msg = "Invalid element"
103+
with self.assertRaises(ParserException) as exc:
104+
_ = self.yaml_reader.to_odml(parsed_doc)
105+
self.assertIn(exc_msg, str(exc.exception))
106+
107+
# Test success on ignore_error parse
108+
self.yaml_reader.ignore_errors = True
109+
doc = self.yaml_reader.to_odml(parsed_doc)
110+
111+
self.assertEqual(len(doc.sections), 1)
112+
self.assertEqual(len(doc.sections["sec"].properties), 1)
113+
114+
self.assertEqual(len(self.yaml_reader.warnings), 3)
115+
for msg in self.yaml_reader.warnings:
116+
self.assertIn("Error", msg)
117+
self.assertTrue(inv_doc_attr in msg or inv_sec_attr in msg or inv_prop_attr in msg)

0 commit comments

Comments
 (0)