示例#1
0
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}))
示例#2
0
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
示例#3
0
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
示例#4
0
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
示例#5
0
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
示例#6
0
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
示例#7
0
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
示例#8
0
def test_to_answer__unsupported_question__exception():
    with pytest.raises(ValueError):
        to_answers([SampleQuestion(SOME_NAME, SOME_STRING)], SOME_NAMESPACE)
示例#9
0
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
示例#10
0
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
示例#11
0
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}))