@@ -73,7 +73,7 @@ def test_from_json_with_invalid_file(self):
7373 d = IODict (filepath )
7474
7575 def test_from_json_with_valid_url_valid_content (self ):
76- url = 'https://jsonplaceholder.typicode .com/users '
76+ url = 'https://raw.githubusercontent .com/fabiocaccamo/python-benedict/master/tests/input/valid-content.json '
7777 # static method
7878 d = IODict .from_json (url )
7979 self .assertTrue (isinstance (d , dict ))
@@ -127,6 +127,113 @@ def test_to_json_file(self):
127127
128128 # YAML
129129
130+ def test_from_toml_with_valid_data (self ):
131+ j = """
132+ a = 1
133+
134+ [b]
135+ c = 3
136+ d = 4
137+ """
138+ # static method
139+ d = IODict .from_toml (j )
140+ self .assertTrue (isinstance (d , dict ))
141+ self .assertEqual (d , { 'a' :1 , 'b' :{ 'c' :3 , 'd' :4 },})
142+ # constructor
143+ d = IODict (j )
144+ self .assertTrue (isinstance (d , dict ))
145+ self .assertEqual (d , { 'a' :1 , 'b' :{ 'c' :3 , 'd' :4 },})
146+
147+ def test_from_toml_with_invalid_data (self ):
148+ j = 'Lorem ipsum est in ea occaecat nisi officia.'
149+ # static method
150+ with self .assertRaises (ValueError ):
151+ d = IODict .from_toml (j )
152+ # constructor
153+ with self .assertRaises (ValueError ):
154+ d = IODict (j )
155+
156+ def test_from_toml_with_valid_file_valid_content (self ):
157+ filepath = self .input_path ('valid-content.toml' )
158+ # static method
159+ d = IODict .from_toml (filepath )
160+ self .assertTrue (isinstance (d , dict ))
161+ # constructor
162+ d = IODict (filepath )
163+ self .assertTrue (isinstance (d , dict ))
164+
165+ def test_from_toml_with_valid_file_invalid_content (self ):
166+ filepath = self .input_path ('invalid-content.toml' )
167+ # static method
168+ with self .assertRaises (ValueError ):
169+ d = IODict .from_toml (filepath )
170+ # constructor
171+ with self .assertRaises (ValueError ):
172+ d = IODict (filepath )
173+
174+ def test_from_toml_with_invalid_file (self ):
175+ filepath = self .input_path ('invalid-file.toml' )
176+ # static method
177+ with self .assertRaises (ValueError ):
178+ d = IODict .from_toml (filepath )
179+ # constructor
180+ with self .assertRaises (ValueError ):
181+ d = IODict (filepath )
182+
183+ # def test_from_toml_with_valid_url_valid_content(self):
184+ # url = 'https://raw.githubusercontent.com/fabiocaccamo/python-benedict/master/tests/input/valid-content.toml'
185+ # # static method
186+ # d = IODict.from_toml(url)
187+ # self.assertTrue(isinstance(d, dict))
188+ # # constructor
189+ # d = IODict(url)
190+ # self.assertTrue(isinstance(d, dict))
191+
192+ def test_from_toml_with_valid_url_invalid_content (self ):
193+ url = 'https://github.com/fabiocaccamo/python-benedict'
194+ # static method
195+ with self .assertRaises (ValueError ):
196+ d = IODict .from_toml (url )
197+ # constructor
198+ with self .assertRaises (ValueError ):
199+ d = IODict (url )
200+
201+ def test_from_toml_with_invalid_url (self ):
202+ url = 'https://github.com/fabiocaccamo/python-benedict-invalid'
203+ # static method
204+ with self .assertRaises (ValueError ):
205+ d = IODict .from_toml (url )
206+ # constructor
207+ with self .assertRaises (ValueError ):
208+ d = IODict (url )
209+
210+ def test_to_toml (self ):
211+ d = IODict ({
212+ 'x' : 7 ,
213+ 'y' : 8 ,
214+ 'z' : 9 ,
215+ 'a' : 1 ,
216+ 'b' : 2 ,
217+ 'c' : 3 ,
218+ })
219+ s = d .to_toml ()
220+ self .assertEqual (d , IODict .from_toml (s ))
221+
222+ def test_to_toml_file (self ):
223+ d = IODict ({
224+ 'x' : 7 ,
225+ 'y' : 8 ,
226+ 'z' : 9 ,
227+ 'a' : 1 ,
228+ 'b' : 2 ,
229+ 'c' : 3 ,
230+ })
231+ filepath = self .output_path ('test_to_toml_file.toml' )
232+ s = d .to_toml (filepath = filepath )
233+ self .assertTrue (d , os .path .isfile (filepath ))
234+ self .assertEqual (d , IODict .from_toml (filepath ))
235+
236+
130237 def test_from_yaml_with_valid_data (self ):
131238 j = """
132239 a: 1
@@ -179,14 +286,14 @@ def test_from_yaml_with_invalid_file(self):
179286 with self .assertRaises (ValueError ):
180287 d = IODict (filepath )
181288
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))
289+ def test_from_yaml_with_valid_url_valid_content (self ):
290+ url = 'https://raw.githubusercontent. com/fabiocaccamo/python-benedict/master /tests/input/valid-content.yml'
291+ # static method
292+ d = IODict .from_yaml (url )
293+ self .assertTrue (isinstance (d , dict ))
294+ # constructor
295+ d = IODict (url )
296+ self .assertTrue (isinstance (d , dict ))
190297
191298 def test_from_yaml_with_valid_url_invalid_content (self ):
192299 url = 'https://github.com/fabiocaccamo/python-benedict'
0 commit comments