@@ -122,70 +122,112 @@ def test_to_json_file(self):
122122 })
123123 filepath = self .output_path ('test_to_json_file.json' )
124124 s = d .to_json (filepath = filepath , sort_keys = True )
125+ self .assertTrue (d , os .path .isfile (filepath ))
125126 self .assertEqual (d , IODict .from_json (filepath ))
126127
127- # def test_from_query_string(self):
128- # pass
128+ # YAML
129129
130- # def test_from_query_string_file(self):
131- # pass
132-
133- # def test_from_query_string_url(self):
134- # pass
135-
136- # def test_from_toml_string(self):
137- # pass
138-
139- # def test_from_toml_file(self):
140- # pass
141-
142- # def test_from_toml_url(self):
143- # pass
144-
145- # def test_from_xml_string(self):
146- # pass
147-
148- # def test_from_xml_file(self):
149- # pass
150-
151- # def test_from_xml_url(self):
152- # pass
153-
154- # def test_from_yaml_string(self):
155- # pass
156-
157- # def test_from_yaml_file(self):
158- # pass
159-
160- # def test_from_yaml_url(self):
161- # pass
162-
163- # def test_to_base64(self):
164- # pass
130+ def test_from_yaml_with_valid_data (self ):
131+ j = """
132+ a: 1
133+ b:
134+ c: 3
135+ d: 4
136+ """
137+ # static method
138+ d = IODict .from_yaml (j )
139+ self .assertTrue (isinstance (d , dict ))
140+ self .assertEqual (d , { 'a' :1 , 'b' :{ 'c' :3 , 'd' :4 },})
141+ # constructor
142+ d = IODict (j )
143+ self .assertTrue (isinstance (d , dict ))
144+ self .assertEqual (d , { 'a' :1 , 'b' :{ 'c' :3 , 'd' :4 },})
165145
166- # def test_to_base64_file(self):
167- # pass
146+ def test_from_yaml_with_invalid_data (self ):
147+ j = 'Lorem ipsum est in ea occaecat nisi officia.'
148+ # static method
149+ with self .assertRaises (ValueError ):
150+ d = IODict .from_yaml (j )
151+ # constructor
152+ with self .assertRaises (ValueError ):
153+ d = IODict (j )
168154
169- # def test_to_query_string(self):
170- # pass
155+ def test_from_yaml_with_valid_file_valid_content (self ):
156+ filepath = self .input_path ('valid-content.yml' )
157+ # static method
158+ d = IODict .from_yaml (filepath )
159+ self .assertTrue (isinstance (d , dict ))
160+ # constructor
161+ d = IODict (filepath )
162+ self .assertTrue (isinstance (d , dict ))
171163
172- # def test_to_query_string_file(self):
173- # pass
164+ def test_from_yaml_with_valid_file_invalid_content (self ):
165+ filepath = self .input_path ('invalid-content.yml' )
166+ # static method
167+ with self .assertRaises (ValueError ):
168+ d = IODict .from_yaml (filepath )
169+ # constructor
170+ with self .assertRaises (ValueError ):
171+ d = IODict (filepath )
174172
175- # def test_to_toml(self):
176- # pass
173+ def test_from_yaml_with_invalid_file (self ):
174+ filepath = self .input_path ('invalid-file.yml' )
175+ # static method
176+ with self .assertRaises (ValueError ):
177+ d = IODict .from_yaml (filepath )
178+ # constructor
179+ with self .assertRaises (ValueError ):
180+ d = IODict (filepath )
177181
178- # def test_to_toml_file(self):
179- # pass
182+ # def test_from_yaml_with_valid_url_valid_content(self):
183+ # url = 'https://github.com/fabiocaccamo/python-benedict/tests/input/valid-content.yml'
184+ # # static method
185+ # d = IODict.from_yaml(url)
186+ # self.assertTrue(isinstance(d, dict))
187+ # # constructor
188+ # d = IODict(url)
189+ # self.assertTrue(isinstance(d, dict))
180190
181- # def test_to_xml(self):
182- # pass
191+ def test_from_yaml_with_valid_url_invalid_content (self ):
192+ url = 'https://github.com/fabiocaccamo/python-benedict'
193+ # static method
194+ with self .assertRaises (ValueError ):
195+ d = IODict .from_yaml (url )
196+ # constructor
197+ with self .assertRaises (ValueError ):
198+ d = IODict (url )
183199
184- # def test_to_xml_file(self):
185- # pass
200+ def test_from_yaml_with_invalid_url (self ):
201+ url = 'https://github.com/fabiocaccamo/python-benedict-invalid'
202+ # static method
203+ with self .assertRaises (ValueError ):
204+ d = IODict .from_yaml (url )
205+ # constructor
206+ with self .assertRaises (ValueError ):
207+ d = IODict (url )
186208
187- # def test_to_yaml(self):
188- # pass
209+ def test_to_yaml (self ):
210+ d = IODict ({
211+ 'x' : 7 ,
212+ 'y' : 8 ,
213+ 'z' : 9 ,
214+ 'a' : 1 ,
215+ 'b' : 2 ,
216+ 'c' : 3 ,
217+ })
218+ s = d .to_yaml ()
219+ self .assertEqual (d , IODict .from_yaml (s ))
189220
190- # def test_to_yaml_file(self):
191- # pass
221+ def test_to_yaml_file (self ):
222+ d = IODict ({
223+ 'x' : 7 ,
224+ 'y' : 8 ,
225+ 'z' : 9 ,
226+ 'a' : 1 ,
227+ 'b' : 2 ,
228+ 'c' : 3 ,
229+ })
230+ filepath = self .output_path ('test_to_yaml_file.yml' )
231+ s = d .to_yaml (filepath = filepath )
232+ self .assertTrue (d , os .path .isfile (filepath ))
233+ self .assertEqual (d , IODict .from_yaml (filepath ))
0 commit comments