コード例 #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])