@@ -18,10 +18,10 @@ def setUp(self):
1818 dir_path = os .path .dirname (os .path .realpath (__file__ ))
1919 self .basepath = os .path .join (dir_path , "resources" )
2020
21- self .yaml_reader = dict_parser .DictReader ()
21+ self .yaml_reader = dict_parser .DictReader (show_warnings = False )
2222
23- dir_name = "odml_%s" % os .path .basename (os .path .splitext (__file__ )[0 ])
24- tmp_dir_path = os .path .join (tempfile .gettempdir (), dir_name )
23+ dir_name = os .path .basename (os .path .splitext (__file__ )[0 ])
24+ tmp_dir_path = os .path .join (tempfile .gettempdir (), "odml_test" , dir_name )
2525
2626 if not os .path .exists (tmp_dir_path ):
2727 os .mkdir (tmp_dir_path )
@@ -156,3 +156,43 @@ def test_sec_creation_error(self):
156156 for msg in self .yaml_reader .warnings :
157157 self .assertIn ("Error" , msg )
158158 self .assertIn (exc_msg , msg )
159+
160+ def test_prop_creation_error (self ):
161+ filename = "broken_property.yaml"
162+ file_content = """Document:
163+ id: 82408bdb-1d9d-4fa9-b4dd-ad78831c797c
164+ sections:
165+ - id: 1111a20a-c02f-4102-a9fe-2e8b77d1d0d2
166+ name: sec
167+ properties:
168+ - id: 1121a20a-c02f-4102-a9fe-2e8b77d1d0d2
169+ name: valid_prop
170+ - id: 1121a20a-c02f-4102-a9fe-2e8b77d1d0d2
171+ name: invalid_prop
172+ type: int
173+ values:
174+ - 'a'
175+ - 'b'
176+ type: test
177+ odml-version: '1.1'
178+ """
179+ parsed_doc = self ._prepare_doc (filename , file_content )
180+
181+ # Test ParserException on default parse
182+ exc_msg = "Property not created"
183+ with self .assertRaises (ParserException ) as exc :
184+ _ = self .yaml_reader .to_odml (parsed_doc )
185+ self .assertIn (exc_msg , str (exc .exception ))
186+
187+ # Test success on ignore_error parse
188+ self .yaml_reader .ignore_errors = True
189+ doc = self .yaml_reader .to_odml (parsed_doc )
190+
191+ self .assertEqual (len (doc .sections ["sec" ].properties ), 1 )
192+ self .assertIn ("valid_prop" , doc .sections ["sec" ].properties )
193+ self .assertNotIn ("invalid_prop" , doc .sections ["sec" ].properties )
194+
195+ self .assertEqual (len (self .yaml_reader .warnings ), 1 )
196+ for msg in self .yaml_reader .warnings :
197+ self .assertIn ("Error" , msg )
198+ self .assertIn (exc_msg , msg )
0 commit comments