-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathtest_debugme.py
95 lines (84 loc) · 2.27 KB
/
test_debugme.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from io import StringIO
from debugme import (
load_recipes,
load_ingredient_locations,
choose_recipes,
get_grocery_items,
)
def test_load_recipes(monkeypatch):
recipe_str = r"""
[
{
"name": "spaghetti bolognese",
"ingredients": [
{"name": "ground beef", "quantity": "1 lb"}
]
}
]
"""
expected = [
{
"name": "spaghetti bolognese",
"ingredients": [
{"name": "ground beef", "quantity": "1 lb"},
],
}
]
monkeypatch.setattr("builtins.open", lambda _: StringIO(recipe_str))
actual = load_recipes(...)
assert actual == expected
def test_load_ingredient_locations(monkeypatch):
ingredients_str = r"""
[
{"name": "avocado", "where": "produce"}
]
"""
expected = {"avocado": "produce"}
monkeypatch.setattr("builtins.open", lambda _: StringIO(ingredients_str))
actual = load_ingredient_locations(...)
assert actual == expected
def test_choose_recipes(monkeypatch):
recipes = [
{
"name": "just beef",
"ingredients": [
{"name": "ground beef", "quantity": "1 lb"},
],
},
{
"name": "just cheese",
"ingredients": [
{"name": "cheese", "quantity": "1 lb"},
],
},
]
monkeypatch.setattr("builtins.input", lambda _: "0,0,1")
expected = [recipes[0], recipes[0], recipes[1]]
actual = choose_recipes(recipes)
assert actual == expected
def test_get_grocery_items():
recipes = [
{
"name": "just beef",
"ingredients": [
{"name": "ground beef", "quantity": "1 lb"},
],
},
{
"name": "just cheese",
"ingredients": [
{"name": "cheese", "quantity": "2 lb"},
],
},
]
ingredients_locs = {
"ground beef": "meat",
"cheese": "dairy",
}
expected = [
{"name": "ground beef", "quantity": "1 lb", "where": "meat"},
{"name": "cheese", "quantity": "2 lb", "where": "dairy"},
]
actual = get_grocery_items(ingredients_locs, recipes)
assert actual == expected
# more tests!