Skip to content

Commit

Permalink
[ADD] add new recipe test
Browse files Browse the repository at this point in the history
  • Loading branch information
guigui0246 committed Oct 15, 2023
1 parent ca9bf43 commit 8b0ca76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _load(self):
self.duration = stime.time_to_sec(i.removeprefix("Duration:").strip())
try:
self.description.strip()
if len(self.description) > 0 and self.description[-1] == '\n':
while len(self.description) > 0 and self.description[-1] == '\n':
self.description = self.description[:-1]
except AttributeError:
pass
Expand Down
24 changes: 23 additions & 1 deletion test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ 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():
Expand Down Expand Up @@ -47,6 +50,9 @@ 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():
Expand All @@ -64,7 +70,7 @@ def test_duration():
@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").description == "Ingot of copper\n\nAnd 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")
Expand All @@ -90,12 +96,20 @@ 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")
Expand All @@ -108,8 +122,16 @@ 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")

0 comments on commit 8b0ca76

Please sign in to comment.