diff --git a/recipe_scrapers/_schemaorg.py b/recipe_scrapers/_schemaorg.py index 01fca868c..977da547f 100644 --- a/recipe_scrapers/_schemaorg.py +++ b/recipe_scrapers/_schemaorg.py @@ -126,6 +126,8 @@ def prep_time(self): return get_minutes(self.data.get("prepTime"), return_zero_on_not_found=True) def yields(self): + if not (self.data.keys() & {"recipeYield", "yield"}): + raise SchemaOrgException("Servings information not found in SchemaOrg") yield_data = self.data.get("recipeYield") or self.data.get("yield") if yield_data and isinstance(yield_data, list): yield_data = yield_data[0] diff --git a/recipe_scrapers/davidlebovitz.py b/recipe_scrapers/davidlebovitz.py index 6ad572a96..0cda81e49 100644 --- a/recipe_scrapers/davidlebovitz.py +++ b/recipe_scrapers/davidlebovitz.py @@ -13,12 +13,6 @@ def author(self): def title(self): return self.schema.title() - def total_time(self): - return self.schema.total_time() - - def yields(self): - return self.schema.yields() - def image(self): return self.schema.image() diff --git a/recipe_scrapers/franzoesischkochen.py b/recipe_scrapers/franzoesischkochen.py index 5ecbdd6eb..3c15eca02 100644 --- a/recipe_scrapers/franzoesischkochen.py +++ b/recipe_scrapers/franzoesischkochen.py @@ -30,6 +30,3 @@ def ingredients(self): def instructions(self): return self.schema.instructions() - - def ratings(self): - return self.schema.ratings() diff --git a/recipe_scrapers/mobkitchen.py b/recipe_scrapers/mobkitchen.py index 4a2afe90c..6e6d32f31 100644 --- a/recipe_scrapers/mobkitchen.py +++ b/recipe_scrapers/mobkitchen.py @@ -54,9 +54,6 @@ def ingredients(self): def instructions(self): return self.schema.instructions() - def ratings(self): - return self.schema.ratings() - def cuisine(self): return self.schema.cuisine() diff --git a/recipe_scrapers/myrecipes.py b/recipe_scrapers/myrecipes.py index 7060f0c35..f84a376a8 100644 --- a/recipe_scrapers/myrecipes.py +++ b/recipe_scrapers/myrecipes.py @@ -24,6 +24,3 @@ def ingredients(self): def instructions(self): return self.schema.instructions() - - def ratings(self): - return self.schema.ratings() diff --git a/recipe_scrapers/southernliving.py b/recipe_scrapers/southernliving.py index a3c13a404..769aed8c3 100644 --- a/recipe_scrapers/southernliving.py +++ b/recipe_scrapers/southernliving.py @@ -43,9 +43,6 @@ def instructions(self): ] ) - def ratings(self): - return self.schema.ratings() - def description(self): des = self.soup.find( "div", diff --git a/recipe_scrapers/springlane.py b/recipe_scrapers/springlane.py index be60262cd..f5ffdbdd6 100644 --- a/recipe_scrapers/springlane.py +++ b/recipe_scrapers/springlane.py @@ -42,6 +42,3 @@ def ingredients(self): def instructions(self): return self.schema.instructions() - - def ratings(self): - return self.schema.ratings() diff --git a/recipe_scrapers/woolworths.py b/recipe_scrapers/woolworths.py index c7b22078e..dd6d3dbec 100644 --- a/recipe_scrapers/woolworths.py +++ b/recipe_scrapers/woolworths.py @@ -68,9 +68,6 @@ def ingredients(self): def instructions(self): return self.schema.instructions() - def ratings(self): - return self.schema.ratings() - def author(self): return self.schema.author() diff --git a/tests/__init__.py b/tests/__init__.py index cc33c9185..77f6cb901 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,3 @@ -import os import unittest from typing import Any, Iterator, Optional, Tuple @@ -23,10 +22,6 @@ def expected_requests(self) -> Iterator[Tuple[str, str, str]]: yield responses.GET, "https://test.example.com", path def setUp(self): - os.environ[ - "RECIPE_SCRAPERS_SETTINGS" - ] = "tests.test_data.test_settings_module.test_settings" - with responses.RequestsMock() as rsps: start_url = None for method, url, path in self.expected_requests: diff --git a/tests/test__settings_module.py b/tests/test__settings_module.py deleted file mode 100644 index 2c5dbaffa..000000000 --- a/tests/test__settings_module.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -import unittest - -from recipe_scrapers.settings import settings - - -class SettingsModuleTest(unittest.TestCase): - def test_default_settings(self): - - os.environ["RECIPE_SCRAPERS_SETTINGS"] = "recipe_scrapers.settings.default" - - self.assertTrue( - len(settings.PLUGINS) > 0, - "There should be some plugins in the default project's settings", - ) - - self.assertFalse( - settings.SUPPRESS_EXCEPTIONS, - "SUPPRESS_EXCEPTIONS should be set to False in the project's default settings", - ) - - def test_settings_change_when_new_module_set(self): - self.assertFalse( - settings.SUPPRESS_EXCEPTIONS, - "SUPPRESS_EXCEPTIONS should be set to False in the project's default settings", - ) - - os.environ[ - "RECIPE_SCRAPERS_SETTINGS" - ] = "tests.test_data.test_settings_module.test_settings" - - self.assertTrue( - settings.SUPPRESS_EXCEPTIONS, - "SUPPRESS_EXCEPTIONS should be set to True after settings are changed with the testing ones", - ) diff --git a/tests/test_cookstr.py b/tests/test_cookstr.py index 0288530d6..6637df285 100644 --- a/tests/test_cookstr.py +++ b/tests/test_cookstr.py @@ -1,5 +1,3 @@ -import os - from recipe_scrapers.cookstr import Cookstr from tests import ScraperTest @@ -23,14 +21,8 @@ def test_title(self): def test_total_time(self): self.assertEqual(60, self.harvester_class.total_time()) - def test_total_yields(self): - self.assertEqual(None, self.harvester_class.yields()) - def test_total_yields_raises_exception(self): - os.environ["RECIPE_SCRAPERS_SETTINGS"] = "recipe_scrapers.settings.default" - - with self.assertRaises(Exception): - self.assertEqual(None, self.harvester_class.yields()) + self.assertRaises(Exception, self.harvester_class.yields) def test_ingredients(self): self.assertCountEqual( diff --git a/tests/test_data/test_settings_module/__init__.py b/tests/test_data/test_settings_module/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/test_data/test_settings_module/test_settings.py b/tests/test_data/test_settings_module/test_settings.py deleted file mode 100644 index 429a4286f..000000000 --- a/tests/test_data/test_settings_module/test_settings.py +++ /dev/null @@ -1,2 +0,0 @@ -SUPPRESS_EXCEPTIONS = True -# LOG_LEVEL = 20 diff --git a/tests/test_davidlebovitz.py b/tests/test_davidlebovitz.py index 098b4ca6e..1df4f7113 100644 --- a/tests/test_davidlebovitz.py +++ b/tests/test_davidlebovitz.py @@ -15,12 +15,6 @@ def test_author(self): def test_title(self): self.assertEqual("Faux Gras", self.harvester_class.title()) - def test_total_time(self): - self.assertEqual(None, self.harvester_class.total_time()) - - def test_yields(self): - self.assertEqual("0 servings", self.harvester_class.yields()) - def test_image(self): self.assertEqual( "https://www.davidlebovitz.com/wp-content/uploads/2015/06/Faux-Gras-Lentil-Pate-8.jpg", diff --git a/tests/test_epicurious.py b/tests/test_epicurious.py index f747b6888..50bab6769 100644 --- a/tests/test_epicurious.py +++ b/tests/test_epicurious.py @@ -21,9 +21,6 @@ def test_title(self): "Ramen Noodle Bowl with Escarole and Spicy Tofu Crumbles", ) - def test_total_time(self): - self.assertEqual(None, self.harvester_class.total_time()) - def test_yields(self): self.assertEqual("2 servings", self.harvester_class.yields()) diff --git a/tests/test_franzoesischkochen.py b/tests/test_franzoesischkochen.py index a47494a48..4e6eb0829 100644 --- a/tests/test_franzoesischkochen.py +++ b/tests/test_franzoesischkochen.py @@ -65,6 +65,3 @@ def test_instructions(self): ), self.harvester_class.instructions(), ) - - def test_ratings(self): - self.assertEqual(None, self.harvester_class.ratings()) diff --git a/tests/test_kwestiasmaku.py b/tests/test_kwestiasmaku.py index 95598928d..0ed5c607d 100644 --- a/tests/test_kwestiasmaku.py +++ b/tests/test_kwestiasmaku.py @@ -15,9 +15,6 @@ def test_author(self): def test_title(self): self.assertEqual("Pieczony kalafior", self.harvester_class.title()) - def test_total_time(self): - self.assertEqual(None, self.harvester_class.total_time()) - def test_yields(self): self.assertEqual("2 servings", self.harvester_class.yields()) diff --git a/tests/test_mobkitchen.py b/tests/test_mobkitchen.py index 67c1968ca..72fbed4b3 100644 --- a/tests/test_mobkitchen.py +++ b/tests/test_mobkitchen.py @@ -59,9 +59,6 @@ def test_instructions(self): self.harvester_class.instructions(), ) - def test_ratings(self): - self.assertEqual(None, self.harvester_class.ratings()) - def test_cuisine(self): self.assertEqual("Indian", self.harvester_class.cuisine()) diff --git a/tests/test_myrecipes.py b/tests/test_myrecipes.py index 5de58f65d..a75f927e4 100644 --- a/tests/test_myrecipes.py +++ b/tests/test_myrecipes.py @@ -1,6 +1,3 @@ -import os - -from recipe_scrapers._exceptions import SchemaOrgException from recipe_scrapers.myrecipes import MyRecipes from tests import ScraperTest @@ -51,13 +48,8 @@ def test_instructions(self): self.harvester_class.instructions(), ) - def test_ratings(self): - self.assertEqual(None, self.harvester_class.ratings()) - def test_ratings_raises_exception(self): - os.environ["RECIPE_SCRAPERS_SETTINGS"] = "recipe_scrapers.settings.default" - with self.assertRaises(SchemaOrgException): - self.assertEqual(None, self.harvester_class.ratings()) + self.assertRaises(Exception, self.harvester_class.ratings) # https://www.myrecipes.com/recipe/cacio-e-pepe diff --git a/tests/test_southernliving.py b/tests/test_southernliving.py index 276c40864..621e07cf3 100644 --- a/tests/test_southernliving.py +++ b/tests/test_southernliving.py @@ -1,6 +1,3 @@ -import os - -from recipe_scrapers._exceptions import SchemaOrgException from recipe_scrapers.southernliving import SouthernLiving from tests import ScraperTest @@ -67,13 +64,8 @@ def test_instructions(self): self.harvester_class.instructions(), ) - def test_ratings_exception_handling(self): - self.assertEqual(None, self.harvester_class.ratings()) - def test_ratings_raises_exception(self): - os.environ["RECIPE_SCRAPERS_SETTINGS"] = "recipe_scrapers.settings.default" - with self.assertRaises(SchemaOrgException): - self.assertEqual(None, self.harvester_class.ratings()) + self.assertRaises(Exception, self.harvester_class.ratings) def test_description(self): self.assertEqual( diff --git a/tests/test_springlane.py b/tests/test_springlane.py index e185d15c5..e825e615c 100644 --- a/tests/test_springlane.py +++ b/tests/test_springlane.py @@ -75,6 +75,3 @@ def test_instructions(self): + "Restliche L\u00f6ffelbiskuits, Espresso und Creme daraufgeben, mindestens 4 Stunden kaltstellen. Vor dem Servieren mit Kakaopulver best\u00e4uben.", self.harvester_class.instructions(), ) - - def test_ratings(self): - self.assertEqual(None, self.harvester_class.ratings()) diff --git a/tests/test_woolworths.py b/tests/test_woolworths.py index b71b63793..517e289f6 100644 --- a/tests/test_woolworths.py +++ b/tests/test_woolworths.py @@ -82,9 +82,6 @@ def test_nutrients(self): def test_language(self): self.assertEqual("en-AU", self.harvester_class.language()) - def test_ratings(self): - self.assertEqual(None, self.harvester_class.ratings()) - def test_site_name(self): self.assertEqual( "Woolworths | Fresh Ideas For You", self.harvester_class.site_name()