@@ 266-316 (lines=51) @@ | ||
263 | truthy: false |
|
264 | """) == sample.__mapper__.text |
|
265 | ||
266 | def test_function_to_json(self, tmpdir): |
|
267 | """Verify standard attribute types dump/parse correctly (function).""" |
|
268 | tmpdir.chdir() |
|
269 | _sample = SampleStandard() |
|
270 | attrs = {'object': self.StatusDictionary, |
|
271 | 'array': IntegerList, |
|
272 | 'string': String, |
|
273 | 'number_int': Integer, |
|
274 | 'number_real': Float, |
|
275 | 'truthy': Boolean, |
|
276 | 'falsey': Boolean} |
|
277 | sample = yorm.sync(_sample, "tmp/directory/sample.json", attrs) |
|
278 | assert "tmp/directory/sample.json" == sample.__mapper__.path |
|
279 | ||
280 | # check defaults |
|
281 | assert {'status': False} == sample.object |
|
282 | assert [] == sample.array |
|
283 | assert "" == sample.string |
|
284 | assert 0 == sample.number_int |
|
285 | assert 0.0 == sample.number_real |
|
286 | assert True is sample.truthy |
|
287 | assert False is sample.falsey |
|
288 | assert None is sample.null |
|
289 | ||
290 | # change object values |
|
291 | sample.object = {'key': 'value'} |
|
292 | sample.array = [1, 2, 3] |
|
293 | sample.string = "Hello, world!" |
|
294 | sample.number_int = 42 |
|
295 | sample.number_real = 4.2 |
|
296 | sample.truthy = None |
|
297 | sample.falsey = 1 |
|
298 | ||
299 | # check file values |
|
300 | assert strip(""" |
|
301 | { |
|
302 | "array": [ |
|
303 | 1, |
|
304 | 2, |
|
305 | 3 |
|
306 | ], |
|
307 | "falsey": true, |
|
308 | "number_int": 42, |
|
309 | "number_real": 4.2, |
|
310 | "object": { |
|
311 | "status": false |
|
312 | }, |
|
313 | "string": "Hello, world!", |
|
314 | "truthy": false |
|
315 | } |
|
316 | """, tabs=2, end='') == sample.__mapper__.text |
|
317 | ||
318 | def test_auto_off(self, tmpdir): |
|
319 | """Verify file updates are disabled with auto save off.""" |
|
@@ 218-264 (lines=47) @@ | ||
215 | assert False is sample.truthy |
|
216 | assert False is sample.falsey |
|
217 | ||
218 | def test_function(self, tmpdir): |
|
219 | """Verify standard attribute types dump/parse correctly (function).""" |
|
220 | tmpdir.chdir() |
|
221 | _sample = SampleStandard() |
|
222 | attrs = {'object': self.StatusDictionary, |
|
223 | 'array': IntegerList, |
|
224 | 'string': String, |
|
225 | 'number_int': Integer, |
|
226 | 'number_real': Float, |
|
227 | 'truthy': Boolean, |
|
228 | 'falsey': Boolean} |
|
229 | sample = yorm.sync(_sample, "tmp/directory/sample.yml", attrs) |
|
230 | assert "tmp/directory/sample.yml" == sample.__mapper__.path |
|
231 | ||
232 | # check defaults |
|
233 | assert {'status': False} == sample.object |
|
234 | assert [] == sample.array |
|
235 | assert "" == sample.string |
|
236 | assert 0 == sample.number_int |
|
237 | assert 0.0 == sample.number_real |
|
238 | assert True is sample.truthy |
|
239 | assert False is sample.falsey |
|
240 | assert None is sample.null |
|
241 | ||
242 | # change object values |
|
243 | sample.object = {'key': 'value'} |
|
244 | sample.array = [1, 2, 3] |
|
245 | sample.string = "Hello, world!" |
|
246 | sample.number_int = 42 |
|
247 | sample.number_real = 4.2 |
|
248 | sample.truthy = None |
|
249 | sample.falsey = 1 |
|
250 | ||
251 | # check file values |
|
252 | assert strip(""" |
|
253 | array: |
|
254 | - 1 |
|
255 | - 2 |
|
256 | - 3 |
|
257 | falsey: true |
|
258 | number_int: 42 |
|
259 | number_real: 4.2 |
|
260 | object: |
|
261 | status: false |
|
262 | string: Hello, world! |
|
263 | truthy: false |
|
264 | """) == sample.__mapper__.text |
|
265 | ||
266 | def test_function_to_json(self, tmpdir): |
|
267 | """Verify standard attribute types dump/parse correctly (function).""" |