Skip to content

Commit bd03939

Browse files
committed
update tests
1 parent da17412 commit bd03939

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

tests/test_io.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
import app.io
77

8-
9-
@pytest.mark.parametrize(
8+
IO_PARAMS = (
109
"name, content, kwargs",
1110
[
1211
("test_file.txt", string.ascii_lowercase, {}),
1312
("test_json_file.json", {"a": 0, "b": 1, "c": 2}, {}),
1413
("test_custom_json.json", {"z": -1, "b": 1, "y": -2, "a": 0}, {"indent": 4, "sort_keys": True}),
1514
],
1615
)
16+
17+
18+
@pytest.mark.parametrize(*IO_PARAMS)
1719
def test_save(tmp_path, name, content, kwargs):
1820
test_path = tmp_path / name
1921
assert not test_path.exists()
@@ -23,17 +25,32 @@ def test_save(tmp_path, name, content, kwargs):
2325
assert test_path.exists()
2426

2527

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-
)
28+
@pytest.mark.parametrize(*IO_PARAMS)
3429
def test_round_trip(tmp_path, name, content, kwargs):
3530
test_path = tmp_path / name
3631
assert not test_path.exists()
3732

3833
app.io.save(test_path, content, **kwargs)
3934
assert app.io.load(test_path) == content
35+
36+
37+
@pytest.mark.asyncio
38+
@pytest.mark.parametrize(*IO_PARAMS)
39+
async def test_async_save(tmp_path, name, content, kwargs):
40+
test_path = tmp_path / name
41+
assert not test_path.exists()
42+
43+
result = await app.io.AIO.save(test_path, content, **kwargs)
44+
assert result == test_path
45+
assert test_path.exists()
46+
47+
48+
@pytest.mark.asyncio
49+
@pytest.mark.parametrize(*IO_PARAMS)
50+
async def test_async_round_trip(tmp_path, name, content, kwargs):
51+
test_path = tmp_path / name
52+
assert not test_path.exists()
53+
54+
await app.io.AIO.save(test_path, content, **kwargs)
55+
load_results = await app.io.AIO.load(test_path)
56+
assert load_results == content

0 commit comments

Comments
 (0)