Commit 36445e60 authored by Niklas Selke's avatar Niklas Selke
Browse files

The 'check_data_capture' function now raises a 'ValueError' if there is any...

The 'check_data_capture' function now raises a 'ValueError' if there is any problem with the given 'data_capture' argument.
parent d3348312
......@@ -249,13 +249,13 @@ def check_seasons(seasons_in, seasons_req):
:param seasons_req: boolean denoting whether the seasons argument is
required
:raises ValueError: raised if the seasons argument is required and
not None and either not a type of list or a
:raises ValueError: raised if the given seasons argument is required
and not None and either not a type of list or a
string or empty or any given season is not
recognized
:return: A list of seasons or None if the seasons argument is either
not needed or None
:return: A list of seasons or None if the given seasons argument is
either not needed or None
"""
if not seasons_req or seasons_in is None:
return None
......@@ -287,12 +287,13 @@ def check_crops(crops_in, crops_req):
:param crops_req: boolean denoting whether the crops argument is
required
:raises ValueError: raised if the crops argument is required and not
None and either not a type of list or a string
or empty or any given crop is not recognized
:raises ValueError: raised if the given crops argument is required
and not None and either not a type of list or a
string or empty or any given crop is not
recognized
:return: A list of crops or None if the crops argument is either
not needed or None
:return: A list of crops or None if the given crops argument is
either not needed or None
"""
if not crops_req or crops_in is None:
return None
......@@ -321,11 +322,18 @@ def check_data_capture(data_capture_in):
:param data_capture_in: the given data capture argument
:return: The processed data capture argument or None if there was a
problem while processing the given data capture argument
:raises ValueError: raised if the given data_capture argument is not
None and either not a float or integer or not
between 0 and 1
:return: A value between 0 and 1 or None if the given data_capture
argument is None
"""
if not isinstance(data_capture_in, (float, int)):
if data_capture_in is None:
return None
if not isinstance(data_capture_in, (float, int)):
raise ValueError("The data_capture argument must be a float or an"
" integer")
if not 0 <= data_capture_in <= 1:
return None
raise ValueError("The data_capture argument must be between 0 and 1")
return data_capture_in
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment