|
| 1 | +"""test.test_io.py""" |
| 2 | +import string |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +import app.io |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "name, content, kwargs", |
| 11 | + [ |
| 12 | + ("test_file.txt", string.ascii_lowercase, {}), |
| 13 | + ("test_json_file.json", {"a": 0, "b": 1, "c": 2}, {}), |
| 14 | + ("test_custom_json.json", {"z": -1, "b": 1, "y": -2, "a": 0}, {"indent": 4, "sort_keys": True}), |
| 15 | + ], |
| 16 | +) |
| 17 | +def test_save(tmp_path, name, content, kwargs): |
| 18 | + test_path = tmp_path / name |
| 19 | + assert not test_path.exists() |
| 20 | + |
| 21 | + result = app.io.save(test_path, content, **kwargs) |
| 22 | + assert result == test_path |
| 23 | + assert test_path.exists() |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.parametrize( |
| 27 | + "name, content, kwargs", |
| 28 | + [ |
| 29 | + ("test_file.txt", string.ascii_lowercase, {}), |
| 30 | + ("test_json_file.json", {"a": 0, "b": 1, "c": 2}, {}), |
| 31 | + ("test_custom_json.json", {"z": -1, "b": 1, "y": -2, "a": 0}, {"indent": 4, "sort_keys": True}), |
| 32 | + ], |
| 33 | +) |
| 34 | +def test_round_trip(tmp_path, name, content, kwargs): |
| 35 | + test_path = tmp_path / name |
| 36 | + assert not test_path.exists() |
| 37 | + |
| 38 | + app.io.save(test_path, content, **kwargs) |
| 39 | + assert app.io.load(test_path) == content |
0 commit comments