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
39 lines (31 loc) · 1.07 KB
/
test_io.py
File metadata and controls
39 lines (31 loc) · 1.07 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
"""test.test_io.py"""
import string
import pytest
import app.io
@pytest.mark.parametrize(
"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}),
],
)
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(
"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}),
],
)
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