forked from ExpDev07/coronavirus-tracker-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_io.py
More file actions
60 lines (45 loc) · 1.53 KB
/
test_io.py
File metadata and controls
60 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""test.test_io.py"""
import string
import pytest
import app.io
IO_PARAMS = (
"name, content, kwargs",
[
("test_file.txt", string.ascii_lowercase, {}),
("test_json_file.json", {"a": 0, "b": 1, "c": 2}, {}),
(
"test_custom_json.json",
{"z": -1, "b": 1, "y": -2, "a": 0},
{"indent": 4, "sort_keys": True},
),
],
)
@pytest.mark.parametrize(*IO_PARAMS)
def test_save(tmp_path, name, content, kwargs):
test_path = tmp_path / name
assert not test_path.exists()
result = app.io.save(test_path, content, **kwargs)
assert result == test_path
assert test_path.exists()
@pytest.mark.parametrize(*IO_PARAMS)
def test_round_trip(tmp_path, name, content, kwargs):
test_path = tmp_path / name
assert not test_path.exists()
app.io.save(test_path, content, **kwargs)
assert app.io.load(test_path) == content
@pytest.mark.asyncio
@pytest.mark.parametrize(*IO_PARAMS)
async def test_async_save(tmp_path, name, content, kwargs):
test_path = tmp_path / name
assert not test_path.exists()
result = await app.io.AIO.save(test_path, content, **kwargs)
assert result == test_path
assert test_path.exists()
@pytest.mark.asyncio
@pytest.mark.parametrize(*IO_PARAMS)
async def test_async_round_trip(tmp_path, name, content, kwargs):
test_path = tmp_path / name
assert not test_path.exists()
await app.io.AIO.save(test_path, content, **kwargs)
load_results = await app.io.AIO.load(test_path)
assert load_results == content