-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_todo.py
More file actions
66 lines (55 loc) · 1.57 KB
/
Copy pathtest_todo.py
File metadata and controls
66 lines (55 loc) · 1.57 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
61
62
63
64
65
66
# tests/test_todo.py
import json
import pytest
from typer.testing import CliRunner
from todo import (DB_READ_ERROR, SUCCESS, __app_name__, __version__, cli, todo)
runner = CliRunner()
def test_version():
result = runner.invoke(cli.app, ["--version"])
assert result.exit_code == 0
assert f"{__app_name__} v{__version__}\n" in result.stdout
@pytest.fixture
def mock_json_file(tmp_path):
todo = [{"Description": "Get some milk.", "Priority": 2, "Done": False}]
db_file = tmp_path / "todo.json"
with db_file.open("w") as db:
json.dump(todo, db, indent=4)
return db_file
test_data1 = {
"description": ["Clean", "the", "house"],
"priority": 1,
"todo": {
"Description": "Clean the house.",
"Priority": 1,
"Done": False,
},
}
test_data2 = {
"description": ["Wash the car"],
"priority": 2,
"todo": {
"Description": "Wash the car.",
"Priority": 2,
"Done": False,
},
}
@pytest.mark.parametrize(
"description, priority, expected",
[
pytest.param(
test_data1["description"],
test_data1["priority"],
(test_data1["todo"], SUCCESS),
),
pytest.param(
test_data2["description"],
test_data2["priority"],
(test_data2["todo"], SUCCESS),
),
],
)
def test_add(mock_json_file, description, priority, expected):
todoer = todo.Todoer(mock_json_file)
assert todoer.add(description, priority) == expected
read = todoer._db_handler.read_todos()
assert len(read.todo_list) == 2