| 308 | |
| 309 | |
| 310 | def test_saving(tmpdir): |
| 311 | o = TD2() |
| 312 | o.three = "set" |
| 313 | dst = Path(tmpdir.join("conf")) |
| 314 | optmanager.save(o, dst, defaults=True) |
| 315 | |
| 316 | o2 = TD2() |
| 317 | optmanager.load_paths(o2, dst) |
| 318 | o2.three = "foo" |
| 319 | optmanager.save(o2, dst, defaults=True) |
| 320 | |
| 321 | optmanager.load_paths(o, dst) |
| 322 | assert o.three == "foo" |
| 323 | |
| 324 | with open(dst, "a") as f: |
| 325 | f.write("foobar: '123'") |
| 326 | optmanager.load_paths(o, dst) |
| 327 | assert o.deferred == {"foobar": "123"} |
| 328 | |
| 329 | with open(dst, "a") as f: |
| 330 | f.write("'''") |
| 331 | with pytest.raises(exceptions.OptionsError): |
| 332 | optmanager.load_paths(o, dst) |
| 333 | |
| 334 | with open(dst, "wb") as f: |
| 335 | f.write(b"\x01\x02\x03") |
| 336 | with pytest.raises(exceptions.OptionsError): |
| 337 | optmanager.load_paths(o, dst) |
| 338 | with pytest.raises(exceptions.OptionsError): |
| 339 | optmanager.save(o, dst) |
| 340 | |
| 341 | with open(dst, "wb") as f: |
| 342 | f.write(b"\xff\xff\xff") |
| 343 | with pytest.raises(exceptions.OptionsError): |
| 344 | optmanager.load_paths(o, dst) |
| 345 | with pytest.raises(exceptions.OptionsError): |
| 346 | optmanager.save(o, dst) |
| 347 | |
| 348 | |
| 349 | def test_merge(): |