diff --git a/tests/__init__.py b/tests/__init__.py index bdb2f120c..af7aed625 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,7 @@ import json import pathlib import unittest +from enum import Enum from typing import Callable from recipe_scrapers import scrape_html @@ -36,7 +37,31 @@ ] OPTIONS_KEY = "_options" -OPTIONS = {"consistent_ingredient_groups": True} + + +class TestOptions(Enum): + CONSISTENT_INGREDIENT_GROUPS = ("consistent_ingredient_groups", True) + """ + Controls if the consistent ingredient groups test is run. + Disable if ingredient groups contain sub-quantities of the same ingredient (as the test will fail). + """ + + def __new__(cls, value: str, default): + obj = object.__new__(cls) + obj._value_ = value + return obj + + def __init__(self, value: str, default: str) -> None: + self.default = default + + +def get_options(expect): + options = {} + for option in TestOptions: + # Checks if the option has been set in the test + # Tolerates both the options node and the specific option not being defined + options[option] = expect.get(OPTIONS_KEY, {}).get(option.value, option.default) + return options class RecipeTestCase(unittest.TestCase): @@ -83,9 +108,7 @@ def test_func(self): ] actual = scrape_html(testhtml.read_text(encoding="utf-8"), host) - options = {} - for option in options.keys(): - options[option] = expect.get(OPTIONS_KEY, {}).get(option, OPTIONS[option]) + options = get_options(expect) # Mandatory tests # If the key isn't present, check an assertion is raised @@ -117,7 +140,7 @@ def test_func(self): msg=f"The actual value for .{key}() did not match the expected value.", ) - if options.get("consistent_ingredient_groups"): + if options.get(TestOptions.CONSISTENT_INGREDIENT_GROUPS): # Assert that the ingredients returned by the ingredient_groups() function # are the same as the ingredients return by the ingredients() function. grouped = [] diff --git a/tests/test_data/ploetzblog.de/ploetzblog.json b/tests/test_data/ploetzblog.de/ploetzblog.json index 2d00d7d66..d11c9abfd 100644 --- a/tests/test_data/ploetzblog.de/ploetzblog.json +++ b/tests/test_data/ploetzblog.de/ploetzblog.json @@ -40,6 +40,6 @@ "total_time": 982, "yields": "1 Stück zu (je) ca. 1050 g", "_options": { - "consitent_ingredient_groups": false + "consistent_ingredient_groups": false } }