Skip to content
Snippets Groups Projects
Commit 198d707d authored by nugget's avatar nugget
Browse files

Move input validation into PlotOption class.

parent a4b89e4b
No related branches found
No related tags found
3 merge requests!12v.0.1 for alpha release,!11Draft: Merge version0.1 changes into dev,!10Version0.1
Pipeline #734413 passed
......@@ -9,7 +9,12 @@ class PlotOptions:
Methods
-------
__init__figs : figure object
__init__
validate_input: Check if input is correct type.
Attributes
----------
figs : figure object
Figure that will be tagged.
prefix : str
Prefix that is placed before the ID.
......@@ -28,3 +33,37 @@ class PlotOptions:
self.id_method = id_method
self.rotation = rotation
self.position = position
def validate_input(self):
"""
Validate if input for PlotOptions is correct type.
Raises
------
TypeError
TypeError is thrown if one of the attributes is not the correct
type.
Returns
-------
0, if all checks succeeded.
"""
# %% Validate inputs
if isinstance(self.prefix, str):
pass
else:
raise TypeError("Prefix is not a string.")
if isinstance(self.figs, list):
pass
else:
raise TypeError("Figures are not a list.")
# TODO: Change id_method key from integer to (more meaningful) string.
try:
self.id_method = int(self.id_method)
except ValueError:
raise TypeError('The chosen ID id_method is not an integer.')
return 0
......@@ -48,23 +48,6 @@ def tagplot(figs, engine, prefix='', id_method=1, location='east'):
figures were given. The first list contains the tagged figures.
The second list contains the corresponding IDs as strings.
"""
# %% Validate inputs
if isinstance(prefix, str):
pass
else:
raise TypeError("Prefix is not a string.")
if isinstance(figs, list):
pass
else:
raise TypeError("Figures are not a list.")
# TODO: Change id_method key from integer to (more meaningful) string.
try:
id_method = int(id_method)
except ValueError:
raise TypeError('The chosen ID id_method is not an integer.')
if isinstance(location, str):
pass
else:
......@@ -99,6 +82,7 @@ def tagplot(figs, engine, prefix='', id_method=1, location='east'):
option_container = PlotOptions(figs, prefix, id_method,
rotation, position)
option_container.validate_input()
match engine:
case 'matplotlib' | 'pyplot':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment