-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_recipe.py
137 lines (118 loc) · 6.55 KB
/
test_recipe.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import pytest
from recipe import Recipe
import os
#
# Loading
#
@pytest.mark.recipe_loading
def test_name():
assert Recipe(os.getcwd() + "/name.recipe", "Result: This is a text").name == "name"
assert Recipe(os.getcwd() + "/name.recipe", "Name: Here").name == "Here"
@pytest.mark.recipe_loading
def test_info():
assert Recipe(os.getcwd() + "/name.recipe", "Result: This is a text").info == "Result: This is a text"
@pytest.mark.recipe_loading
def test_results():
assert Recipe(os.getcwd() + "/name.recipe", "Result: copper_dust").results == {"copper_dust": 1}
assert Recipe(os.getcwd() + "/name.recipe", "Result: copper_dustx2").results == {"copper_dust": 2}
assert Recipe(os.getcwd() + "/name.recipe", "Result: copper_dust copper_ingot").results == {"copper_dust": 1, "copper_ingot":1}
assert Recipe(os.getcwd() + "/name.recipe", "Result: copper_dust\tcopper_ingot").results == {"copper_dust": 1, "copper_ingot":1}
assert Recipe(os.getcwd() + "/name.recipe", "Result: copper_dust;copper_ingot").results == {"copper_dust": 1, "copper_ingot":1}
assert Recipe(os.getcwd() + "/name.recipe", "Result: copper_dust,copper_ingot").results == {"copper_dust": 1, "copper_ingot":1}
@pytest.mark.recipe_loading
def test_crafter():
assert Recipe(os.getcwd() + "/name.recipe", "Crafter: fast_oven").crafter == ["fast_oven"]
liste2 = ["fast_oven", "slow_oven"]
liste2.sort()
liste = Recipe(os.getcwd() + "/name.recipe", "Crafter: fast_oven;slow_oven").crafter
liste.sort()
assert liste == liste2
liste = Recipe(os.getcwd() + "/name.recipe", "Crafter: fast_oven\tslow_oven").crafter
liste.sort()
assert liste == liste2
liste = Recipe(os.getcwd() + "/name.recipe", "Crafter: fast_oven slow_oven").crafter
liste.sort()
assert liste == liste2
liste = Recipe(os.getcwd() + "/name.recipe", "Crafter: fast_oven,slow_oven").crafter
liste.sort()
assert liste == liste2
liste = Recipe(os.getcwd() + "/name.recipe", "Crafter: fast_oven\t;;; slow_oven").crafter
liste.sort()
assert liste == liste2
@pytest.mark.recipe_loading
def test_ressource():
assert Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust").ressources == {"copper_dust": 1}
assert Recipe(os.getcwd() + "/name.recipe", "Ressources: 3xcopper_dust").ressources == {"copper_dust": 3}
assert Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust copper_ingot").ressources == {"copper_dust": 1, "copper_ingot":1}
assert Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust;copper_ingot").ressources == {"copper_dust": 1, "copper_ingot":1}
assert Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust\tcopper_ingot").ressources == {"copper_dust": 1, "copper_ingot":1}
assert Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust,copper_ingot").ressources == {"copper_dust": 1, "copper_ingot":1}
@pytest.mark.recipe_loading
def test_crafter_needed():
assert Recipe(os.getcwd() + "/name.recipe", "Crafter needed: True").crafter_needed == True
assert Recipe(os.getcwd() + "/name.recipe", "Crafter needed").crafter_needed == True
assert Recipe(os.getcwd() + "/name.recipe", "Crafter needed: False").crafter_needed == False
assert Recipe(os.getcwd() + "/name.recipe", "Name: Here").crafter_needed == False
@pytest.mark.recipe_loading
def test_duration():
import const
from stime import time_to_sec
assert Recipe(os.getcwd() + "/name.recipe", f"Duration: 1{const.DAY_STRING}1{const.MINUTE_STRING}").duration == time_to_sec(f"1{const.DAY_STRING}1{const.MINUTE_STRING}")
@pytest.mark.recipe_loading
def test_description():
assert Recipe(os.getcwd() + "/name.recipe", "Description: Ingot of copper").description == "Ingot of copper"
assert Recipe(os.getcwd() + "/name.recipe", "Description: Ingot of copper\n\nAnd of copper\n\n\n").description == "Ingot of copper\n\nAnd of copper"
from default import DEFAULT_RECIPE_DESCRIPTION
from stime import sec_to_time
a = Recipe(os.getcwd() + "/name.recipe", "This is a text")
assert a.infos() == a.description == DEFAULT_RECIPE_DESCRIPTION.format(a.name, a.ressources, a.results, a.crafter, "" if a.crafter_needed else "not", sec_to_time(a.duration))
#
# Utilisation
#
@pytest.mark.recipe
def test_repr():
repr(Recipe(os.getcwd() + "/name.crafter", f"")) == "name"
@pytest.mark.recipe
def test_uses_dict():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
assert a.uses() == {"copper_dust":1}
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: 3xcopper_dust \n Result: 3xcopper_ingot copper_dust")
assert a.uses() == {"copper_dust":2}
@pytest.mark.recipe
def test_uses_item():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
assert a.uses("copper_dust")
assert not a.uses("copper_ingot")
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust 2xcopper_ingot \n Result: copper_ingot")
assert a.uses("copper_ingot")
@pytest.mark.recipe
def test_uses_unknown():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
assert not a.uses("name")
@pytest.mark.recipe
def test_uses_neg():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
a.ressources["copper_dust"] = 0
assert not a.uses("copper_dust")
@pytest.mark.recipe
def test_prod_dict():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
assert a.produce() == {"copper_ingot":1}
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: 3xcopper_dust copper_ingot \n Result: 3xcopper_ingot")
assert a.produce() == {"copper_ingot":2}
@pytest.mark.recipe
def test_prod_item():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
assert a.produce("copper_ingot")
assert not a.produce("copper_dust")
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust copper_ingot \n Result: 2xcopper_ingot")
assert a.produce("copper_ingot")
@pytest.mark.recipe
def test_prod_unknown():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
assert not a.produce("name")
@pytest.mark.recipe
def test_prod_neg():
a = Recipe(os.getcwd() + "/name.recipe", "Ressources: copper_dust \n Result: copper_ingot")
a.results["copper_ingot"] = 0
assert not a.produce("copper_ingot")