def test_to_answer__basic_question_value_not_valid__exception(): questions = [ BasicQuestion( SOME_NAME, SOME_STRING, SOME_DEFAULT, validator=lambda v, a: ValidationFailure("some-error"), ) ] with pytest.raises(CliException): with pytest.deprecated_call(): to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING}))
def test_to_answer__confirm_value_set__set_value(): questions = [Confirm(SOME_NAME, SOME_STRING, default=SOME_BOOL)] answers = to_answers(questions, Namespace(**{SOME_NAME: SOME_OTHER_BOOL})) assert SOME_NAME in answers assert answers[SOME_NAME] == SOME_OTHER_BOOL
def test_to_answer__choice_value_not_set__default(): questions = [Choice(SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT)] answers = to_answers(questions, Namespace()) assert SOME_NAME in answers assert answers[SOME_NAME] == SOME_DEFAULT
def test_to_answer__basic_question_value_set__set_value(): questions = [BasicQuestion(SOME_NAME, SOME_STRING, SOME_DEFAULT)] answers = to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING})) assert SOME_NAME in answers assert answers[SOME_NAME] == SOME_STRING
def test_to_answer__choice_value_set__set_value(): questions = [Choice(SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT)] answers = to_answers(questions, Namespace(**{SOME_NAME: SOME_NON_DEFAULT_OPTION})) assert SOME_NAME in answers assert answers[SOME_NAME] == SOME_NON_DEFAULT_OPTION
def test_to_answer__basic_question_dont_ask__value_not_stored(): questions = [ BasicQuestion(SOME_NAME, SOME_STRING, SOME_DEFAULT, should_ask=lambda _: False) ] result = to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING})) assert SOME_NAME not in result
def test_to_answer__choice_dont_ask__value_not_stored(): questions = [ Choice( SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT, should_ask=lambda _: False, ) ] result = to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING})) assert SOME_NAME not in result
def test_to_answer__unsupported_question__exception(): with pytest.raises(ValueError): to_answers([SampleQuestion(SOME_NAME, SOME_STRING)], SOME_NAMESPACE)
def test_to_answer__echo__value_not_stored(): questions = [Echo(SOME_STRING)] result = to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING})) assert SOME_NAME not in result
def test_to_answer__confirm_dont_ask__value_not_stored(): questions = [Confirm(SOME_NAME, SOME_STRING, should_ask=lambda _: False)] result = to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING})) assert SOME_NAME not in result
def test_to_answer__choice_value_not_valid__exception(): questions = [Choice(SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT)] with pytest.raises(CliException): to_answers(questions, Namespace(**{SOME_NAME: SOME_STRING}))