Merge pull request #1134 from YunoHost/fix-boolean-arg-parse

fix boolean arg parse
This commit is contained in:
Alexandre Aubin 2021-01-13 23:04:32 +01:00 committed by GitHub
commit 1e7c3ffc21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -2537,10 +2537,10 @@ class BooleanArgumentParser(YunoHostArgumentFormatParser):
if isinstance(question.value, bool):
return 1 if question.value else 0
if str(question.value).lower() in ["1", "yes", "y"]:
if str(question.value).lower() in ["1", "yes", "y", "true"]:
return 1
if str(question.value).lower() in ["0", "no", "n"]:
if str(question.value).lower() in ["0", "no", "n", "false"]:
return 0
raise YunohostError('app_argument_choice_invalid', name=question.name,

View file

@ -616,6 +616,18 @@ def test_parse_args_in_yunohost_format_boolean_all_yes():
_parse_args_in_yunohost_format({"some_boolean": True}, questions) ==
expected_result
)
assert (
_parse_args_in_yunohost_format({"some_boolean": "True"}, questions) ==
expected_result
)
assert (
_parse_args_in_yunohost_format({"some_boolean": "TRUE"}, questions) ==
expected_result
)
assert (
_parse_args_in_yunohost_format({"some_boolean": "true"}, questions) ==
expected_result
)
def test_parse_args_in_yunohost_format_boolean_all_no():
@ -653,6 +665,18 @@ def test_parse_args_in_yunohost_format_boolean_all_no():
_parse_args_in_yunohost_format({"some_boolean": False}, questions) ==
expected_result
)
assert (
_parse_args_in_yunohost_format({"some_boolean": "False"}, questions) ==
expected_result
)
assert (
_parse_args_in_yunohost_format({"some_boolean": "FALSE"}, questions) ==
expected_result
)
assert (
_parse_args_in_yunohost_format({"some_boolean": "false"}, questions) ==
expected_result
)
# XXX apparently boolean are always False (0) by default, I'm not sure what to think about that