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