예제 #1
0
def test_create_parser__basic_question__value():
    parser = create_parser(
        [BasicQuestion(SOME_NAME, SOME_STRING, SOME_DEFAULT)])

    result = parser.parse_args([SOME_ARG_NAME, SOME_STRING])

    assert vars(result)[SOME_NAME] is SOME_STRING
예제 #2
0
def test_create_parser__choice__choice_valid(choice):
    parser = create_parser(
        [Choice(SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT)])

    result = parser.parse_args([SOME_ARG_NAME, choice])

    assert vars(result)[SOME_NAME] == choice
예제 #3
0
def test_create_parser__choice_not_given__no_value():
    parser = create_parser(
        [Choice(SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT)])

    result = parser.parse_args([])

    assert vars(result)[SOME_NAME] is None
예제 #4
0
def test_create_parser__choice_dynamic_options_invalid_option__value_stored():
    # dynamic options can't be statically validated, so we store any value
    parser = create_parser(
        [Choice(SOME_NAME, SOME_STRING, some_dynamic_options, SOME_DEFAULT)])

    result = parser.parse_args([SOME_ARG_NAME, SOME_INVALID_OPTION])

    assert vars(result)[SOME_NAME] == SOME_INVALID_OPTION
예제 #5
0
def test_create_parser__unsupported_question__exception():
    with pytest.raises(ValueError):
        create_parser([SampleQuestion(SOME_NAME, SOME_STRING)])
예제 #6
0
def test_create_parser__confirm_no_option__false():
    parser = create_parser([Confirm(SOME_NAME, SOME_STRING)])

    result = parser.parse_args([canonical_arg_name(f"no-{SOME_NAME}")])

    assert vars(result)[SOME_NAME] is False
예제 #7
0
def test_create_parser__confirm_main_option__true():
    parser = create_parser([Confirm(SOME_NAME, SOME_STRING)])

    result = parser.parse_args([SOME_ARG_NAME])

    assert vars(result)[SOME_NAME] is True
예제 #8
0
def test_create_parser__confirm_not_given__no_value():
    parser = create_parser([Confirm(SOME_NAME, SOME_STRING)])

    result = parser.parse_args([])

    assert vars(result)[SOME_NAME] is None
예제 #9
0
def test_create_parser__choice_invalid_option__exception():
    parser = create_parser(
        [Choice(SOME_NAME, SOME_STRING, SOME_OPTIONS, SOME_DEFAULT)])

    with pytest.raises(SystemExit):
        parser.parse_args([SOME_ARG_NAME, SOME_INVALID_OPTION])