-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_add_variety2.py
More file actions
executable file
·66 lines (47 loc) · 1.57 KB
/
test_add_variety2.py
File metadata and controls
executable file
·66 lines (47 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
"""Test the tasks.add() API function."""
import pytest
import tasks
from tasks import Task
tasks_to_try = (
Task("sleep", done=True),
Task("wake", "brian"),
Task("breathe", "BRIAN", True),
Task("exercise", "BrIaN", False),
)
task_ids = ["Task({},{},{})".format(t.summary, t.owner, t.done) for t in tasks_to_try]
def equivalent(t1, t2):
"""Check two tasks for equivalence."""
return (
(t1.summary == t2.summary) and (t1.owner == t2.owner) and (t1.done == t2.done)
)
@pytest.fixture(params=tasks_to_try)
def a_task(request):
"""Using no ids."""
return request.param
def test_add_a(tasks_db, a_task):
"""Using a_task fixture (no ids)."""
task_id = tasks.add(a_task)
t_from_db = tasks.get(task_id)
assert equivalent(t_from_db, a_task)
@pytest.fixture(params=tasks_to_try, ids=task_ids)
def b_task(request):
"""Using a list of ids."""
return request.param
def test_add_b(tasks_db, b_task):
"""Using b_task fixture, with ids."""
task_id = tasks.add(b_task)
t_from_db = tasks.get(task_id)
assert equivalent(t_from_db, b_task)
def id_func(fixture_value):
"""A function for generating ids."""
t = fixture_value
return "Task({},{},{})".format(t.summary, t.owner, t.done)
@pytest.fixture(params=tasks_to_try, ids=id_func)
def c_task(request):
"""Using a function (id_func) to generate ids."""
return request.param
def test_add_c(tasks_db, c_task):
"""Use fixture with generated ids."""
task_id = tasks.add(c_task)
t_from_db = tasks.get(task_id)
assert equivalent(t_from_db, c_task)