mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-05 09:55:17 -05:00
Fix issue with parsing scraped nutrition (#732)
* Fix issue with parsing scraped nutrition * Attempt to clean nutrition info * Allow comma separator * Fix return type for clean_nutrition. Fail safe in case of unexpected type from scraper * Switch to using regex parsing * Formatting * Cleanup - empty strings no longer a concern
This commit is contained in:
@@ -58,6 +58,24 @@ def test_clean_image():
|
||||
assert cleaner.image(["My URL!", "MY SECOND URL"]) == "My URL!"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"nutrition,expected",
|
||||
[
|
||||
(None, {}),
|
||||
({"calories": "105 kcal"}, {"calories": "105"}),
|
||||
({"calories": "105 kcal 104 sugar"}, {"calories": "105"}),
|
||||
({"calories": ""}, {}),
|
||||
({"calories": ["not just a string"], "sugarContent": "but still tries 555.321"}, {"sugarContent": "555.321"}),
|
||||
({"sodiumContent": "5.1235g"}, {"sodiumContent": "5123.5"}),
|
||||
({"sodiumContent": "5mg"}, {"sodiumContent": "5"}),
|
||||
({"sodiumContent": "10oz"}, {"sodiumContent": "10"}),
|
||||
({"sodiumContent": "10.1.2g"}, {"sodiumContent": "10100.0"}),
|
||||
],
|
||||
)
|
||||
def test_clean_nutrition(nutrition, expected):
|
||||
assert cleaner.clean_nutrition(nutrition) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"instructions",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user