mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #1134 from YunoHost/fix-boolean-arg-parse
fix boolean arg parse
This commit is contained in:
commit
1e7c3ffc21
2 changed files with 26 additions and 2 deletions
|
@ -2537,10 +2537,10 @@ class BooleanArgumentParser(YunoHostArgumentFormatParser):
|
||||||
if isinstance(question.value, bool):
|
if isinstance(question.value, bool):
|
||||||
return 1 if question.value else 0
|
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
|
return 1
|
||||||
|
|
||||||
if str(question.value).lower() in ["0", "no", "n"]:
|
if str(question.value).lower() in ["0", "no", "n", "false"]:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
raise YunohostError('app_argument_choice_invalid', name=question.name,
|
raise YunohostError('app_argument_choice_invalid', name=question.name,
|
||||||
|
|
|
@ -616,6 +616,18 @@ def test_parse_args_in_yunohost_format_boolean_all_yes():
|
||||||
_parse_args_in_yunohost_format({"some_boolean": True}, questions) ==
|
_parse_args_in_yunohost_format({"some_boolean": True}, questions) ==
|
||||||
expected_result
|
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():
|
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) ==
|
_parse_args_in_yunohost_format({"some_boolean": False}, questions) ==
|
||||||
expected_result
|
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
|
# XXX apparently boolean are always False (0) by default, I'm not sure what to think about that
|
||||||
|
|
Loading…
Add table
Reference in a new issue