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
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
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
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
def test_create_parser__unsupported_question__exception(): with pytest.raises(ValueError): create_parser([SampleQuestion(SOME_NAME, SOME_STRING)])
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
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
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
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])