[mod] moar test for arguments parsing

This commit is contained in:
Laurent Peuch 2020-05-16 01:42:41 +02:00
parent 58ce6e5e58
commit ec9b020376

View file

@ -98,6 +98,32 @@ def test_parse_args_in_yunohost_format_string_no_input_optional():
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
def test_parse_args_in_yunohost_format_string_optional_with_input():
questions = [{
"name": "some_string",
"ask": "some question",
"optional": True,
}]
answers = {}
expected_result = OrderedDict({"some_string": ("some_value", "string")})
with patch.object(msignals, "prompt", return_value="some_value"):
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
@pytest.mark.skip # this should work without ask
def test_parse_args_in_yunohost_format_string_optional_with_input_without_ask():
questions = [{
"name": "some_string",
"optional": True,
}]
answers = {}
expected_result = OrderedDict({"some_string": ("some_value", "string")})
with patch.object(msignals, "prompt", return_value="some_value"):
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
def test_parse_args_in_yunohost_format_string_no_input_default():
questions = [{
"name": "some_string",
@ -107,3 +133,65 @@ def test_parse_args_in_yunohost_format_string_no_input_default():
answers = {}
expected_result = OrderedDict({"some_string": ("some_value", "string")})
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
def test_parse_args_in_yunohost_format_string_input_test_ask():
ask_text = "some question"
questions = [{
"name": "some_string",
"ask": ask_text,
}]
answers = {}
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
_parse_args_in_yunohost_format(answers, questions)
prompt.assert_called_with(ask_text, False)
def test_parse_args_in_yunohost_format_string_input_test_ask_with_default():
ask_text = "some question"
default_text = "some example"
questions = [{
"name": "some_string",
"ask": ask_text,
"default": default_text,
}]
answers = {}
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
_parse_args_in_yunohost_format(answers, questions)
prompt.assert_called_with("%s (default: %s)" % (ask_text, default_text), False)
@pytest.mark.skip # we should do something with this example
def test_parse_args_in_yunohost_format_string_input_test_ask_with_example():
ask_text = "some question"
example_text = "some example"
questions = [{
"name": "some_string",
"ask": ask_text,
"example": example_text,
}]
answers = {}
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
_parse_args_in_yunohost_format(answers, questions)
assert ask_text in prompt.call_args[0]
assert example_text in prompt.call_args[0]
@pytest.mark.skip # we should do something with this help
def test_parse_args_in_yunohost_format_string_input_test_ask_with_help():
ask_text = "some question"
help_text = "some_help"
questions = [{
"name": "some_string",
"ask": ask_text,
"help": help_text,
}]
answers = {}
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
_parse_args_in_yunohost_format(answers, questions)
assert ask_text in prompt.call_args[0]
assert help_text in prompt.call_args[0]