Sfoglia il codice sorgente

add test for recipe parser

Daniel Sheffield 1 anno fa
parent
commit
c4aa03e6d4
4 ha cambiato i file con 58 aggiunte e 2 eliminazioni
  1. 0 2
      app/parse_recipe.py
  2. 0 0
      test/__init__.py
  3. 0 0
      test/rest/__init__.py
  4. 58 0
      test/test_parse_recipe.py

+ 0 - 2
app/parse_recipe.py

@@ -30,5 +30,3 @@ def parse_recipe(fh, query_manager: QueryManager):
         if k in contents:
             recipe[k] = contents[k]
     return recipe
-
-

+ 0 - 0
test/__init__.py


+ 0 - 0
test/rest/__init__.py


+ 58 - 0
test/test_parse_recipe.py

@@ -0,0 +1,58 @@
+#
+# Copyright (c) Daniel Sheffield 2023
+#
+# All rights reserved
+#
+# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
+from pytest import fixture
+from app.parse_recipe import parse_recipe
+from app.data.QueryManager import QueryManager
+from app.rest import ALL_UNITS
+
+@fixture
+def blank_recipe():
+    with open('recipes/Blank.yaml') as fh:
+        yield fh
+    return
+
+@fixture
+def matzo_recipe():
+    with open('recipes/Matzo.yaml') as fh:
+        yield fh
+    return
+
+@fixture
+def units():
+    return ALL_UNITS | set([
+        'Cup (metric)',
+        'tsp (metric)',
+    ])
+
+@fixture
+def query_manager(units):
+    qm = QueryManager(None, None)
+    qm.unique_suggestions = lambda *_1, **_2: units
+    return qm
+
+def test_parse_blank_recipe(query_manager, blank_recipe):
+    assert parse_recipe(blank_recipe, query_manager) == {
+        'ingredients': [],
+        'feeds': 1,
+        'instructions': '',
+    }
+
+def test_parse_matzo_recipe(query_manager, matzo_recipe):
+    assert parse_recipe(matzo_recipe, query_manager) == {
+        'ingredients': [
+            ['Wheat Berries', '241', 'g'],
+            ['Olive Oil', '0.25', 'Cup (metric)'],
+            ['Salt', '1', 'tsp (metric)']],
+        'feeds': 16,
+        'instructions': """Soak **Wheat Berries** and sprout. Dehydrate in oven. Grind into flour.
+Preheat oven to 200C.
+Combine 150 grams of warm water with **Salt**.
+Mix **Olive Oil** and flour and water into a dough.
+Roll out into an oval. Score.
+Bake at 200C for 5 minutes, flip and repeat."""
+    }
+