Пример #1
0
def test_validate_configuration_format_with_extra_section_should_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section', 'extra'))
    config_format = (module.Section_format('section', options=()), )

    with assert_raises(ValueError):
        module.validate_configuration_format(parser, config_format)
Пример #2
0
def test_validate_configuration_format_with_unknown_section_should_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section', 'extra'))
    config_format = (
        module.Section_format('section', options=()),
    )

    with assert_raises(ValueError):
        module.validate_configuration_format(parser, config_format)
Пример #3
0
def test_validate_configuration_format_with_extra_option_should_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section', ))
    parser.should_receive('options').with_args('section').and_return(
        ('option', 'extra'))
    config_format = (module.Section_format(
        'section',
        options=(module.Config_option('option', str, required=True), ),
    ), )

    with assert_raises(ValueError):
        module.validate_configuration_format(parser, config_format)
Пример #4
0
def test_validate_configuration_format_with_extra_option_should_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section',))
    parser.should_receive('options').with_args('section').and_return(('option', 'extra'))
    config_format = (
        module.Section_format(
            'section',
            options=(module.Config_option('option', str, required=True),),
        ),
    )

    with assert_raises(ValueError):
        module.validate_configuration_format(parser, config_format)
Пример #5
0
def test_validate_configuration_format_with_missing_optional_option_should_not_raise(
):
    parser = flexmock()
    parser.should_receive('sections').and_return(('section', ))
    parser.should_receive('options').with_args('section').and_return(
        ('option', ))
    config_format = (module.Section_format(
        'section',
        options=(
            module.Config_option('option', str, required=True),
            module.Config_option('missing', str, required=False),
        ),
    ), )

    module.validate_configuration_format(parser, config_format)
Пример #6
0
def test_validate_configuration_format_with_missing_optional_option_should_not_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section',))
    parser.should_receive('options').with_args('section').and_return(('option',))
    config_format = (
        module.Section_format(
            'section',
            options=(
                module.Config_option('option', str, required=True),
                module.Config_option('missing', str, required=False),
            ),
        ),
    )

    module.validate_configuration_format(parser, config_format)
Пример #7
0
def test_validate_configuration_format_with_valid_config_should_not_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section', 'other'))
    parser.should_receive('options').with_args('section').and_return(
        ('stuff', ))
    parser.should_receive('options').with_args('other').and_return(('such', ))
    config_format = (
        module.Section_format(
            'section',
            options=(module.Config_option('stuff', str, required=True), ),
        ),
        module.Section_format(
            'other',
            options=(module.Config_option('such', str, required=True), ),
        ),
    )

    module.validate_configuration_format(parser, config_format)
Пример #8
0
def test_validate_configuration_format_with_valid_config_should_not_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section', 'other'))
    parser.should_receive('options').with_args('section').and_return(('stuff',))
    parser.should_receive('options').with_args('other').and_return(('such',))
    config_format = (
        module.Section_format(
            'section',
            options=(
                module.Config_option('stuff', str, required=True),
            ),
        ),
        module.Section_format(
            'other',
            options=(
                module.Config_option('such', str, required=True),
            ),
        ),
    )

    module.validate_configuration_format(parser, config_format)
Пример #9
0
def test_validate_configuration_format_with_missing_required_section_should_raise():
    parser = flexmock()
    parser.should_receive('sections').and_return(('section',))
    config_format = (
        module.Section_format(
            'section',
            options=(
                module.Config_option('stuff', str, required=True),
            ),
        ),
        # At least one option in this section is required, so the section is required.
        module.Section_format(
            'missing',
            options=(
                module.Config_option('such', str, required=False),
                module.Config_option('things', str, required=True),
            ),
        ),
    )

    with assert_raises(ValueError):
        module.validate_configuration_format(parser, config_format)