@@ -115,3 +115,44 @@ def test_invalid_attribute_handling(self):
115
115
for msg in self .yaml_reader .warnings :
116
116
self .assertIn ("Error" , msg )
117
117
self .assertTrue (inv_doc_attr in msg or inv_sec_attr in msg or inv_prop_attr in msg )
118
+
119
+ def test_sec_creation_error (self ):
120
+ filename = "broken_section.yaml"
121
+
122
+ valid = "valid_sec"
123
+ invalid = "invalid_sec"
124
+
125
+ file_content = """Document:
126
+ id: 82408bdb-1d9d-4fa9-b4dd-ad78831c797c
127
+ sections:
128
+ - id: 1111a20a-c02f-4102-a9fe-2e8b77d1d0d2
129
+ name: sec
130
+ sections:
131
+ - id: 1121a20a-c02f-4102-a9fe-2e8b77d1d0d2
132
+ name: %s
133
+ type: test
134
+ - id: [I-am-so-kaputt]
135
+ name: %s
136
+ type: test
137
+ odml-version: '1.1'
138
+ """ % (valid , invalid )
139
+ parsed_doc = self ._prepare_doc (filename , file_content )
140
+
141
+ # Test ParserException on default parse
142
+ exc_msg = "Section not created"
143
+ with self .assertRaises (ParserException ) as exc :
144
+ _ = self .yaml_reader .to_odml (parsed_doc )
145
+ self .assertIn (exc_msg , str (exc .exception ))
146
+
147
+ # Test success on ignore_error parse
148
+ self .yaml_reader .ignore_errors = True
149
+ doc = self .yaml_reader .to_odml (parsed_doc )
150
+
151
+ self .assertEqual (len (doc .sections ["sec" ].sections ), 1 )
152
+ self .assertIn (valid , doc .sections ["sec" ].sections )
153
+ self .assertNotIn (invalid , doc .sections ["sec" ].sections )
154
+
155
+ self .assertEqual (len (self .yaml_reader .warnings ), 1 )
156
+ for msg in self .yaml_reader .warnings :
157
+ self .assertIn ("Error" , msg )
158
+ self .assertIn (exc_msg , msg )
0 commit comments