hhursev / recipe-scrapers

Python package for scraping recipes data
MIT License
1.73k stars 527 forks source link

Utils: reject empty input in `get_yields` #1314

Closed jayaddison closed 1 week ago

jayaddison commented 2 weeks ago

Resolves #1313.

jknndy commented 2 weeks ago

When I apply these changes to #1307 test case _3 is still expecting 0 servings . Not sure what's causing it yet

jayaddison commented 1 week ago

Ah, I think it's that this str(...) typecast turns a None value into the string 'None'.

That input -- and a bunch of other nonsense inputs, seem to return 0 servings:

>>> from recipe_scrapers._utils import get_yields
>>> get_yields('None')
'0 servings'
>>> get_yields('N one')
'0 servings'
>>> get_yields('N')
'0 servings'
>>> get_yields('n')
'0 servings'
>>> get_yields('adsf')
'0 servings'
jayaddison commented 1 week ago

I think we can prevent the typecasting of None to 'None' -- but I can't think of an easy way to validate other non-empty strings.