Skip to content

Commit

Permalink
Merge pull request #178 from PDXCapstoneF/mab-add-dialogue-types
Browse files Browse the repository at this point in the history
Add type-checking to dialogue create_run function
  • Loading branch information
mbottini committed May 17, 2018
2 parents d0766fc + 44db7d9 commit b608c6b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions dialogue.py
Expand Up @@ -18,6 +18,14 @@
TEMPLATE_TRANS = 'translations'
TEMPLATE_DEFAULT = 'prop_options'

TYPE_CHECK_FUNC = {
'string' : lambda x : str(x),
'int' : lambda x : int(x),
'integer' : lambda x : int(x),
'float' : lambda x : float(x),
'bool' : lambda x : x not in set(['false', 'False']),
'boolean' : lambda x : x not in set(['false', 'False']),
}

def write_json(filename, python_dict):
"""
Expand Down Expand Up @@ -116,8 +124,14 @@ def create_run(run_list, template_dict):
template_dict[template_type]['annotations'][arg],
template_dict[template_type]['types'][arg]))
else:
new_run[RUNLIST_ARGS][arg] = user_input
break
try:
type_func = TYPE_CHECK_FUNC[
template_dict[template_type][TEMPLATE_TYPES][arg]]
user_input = type_func(user_input)
new_run[RUNLIST_ARGS][arg] = user_input
break
except:
print('Invalid input.')
except:
print('Invalid input.')
while True:
Expand Down

0 comments on commit b608c6b

Please sign in to comment.