示例#1
0
def test_parse_section_options_with_punctuation_should_return_section_options():
    parser = module.RawConfigParser()
    parser.readfp(StringIO('[section]\nfoo: {}\n'.format(string.punctuation)))

    section_format = module.Section_format(
        'section',
        (module.Config_option('foo', str, required=True),),
    )

    config = module.parse_section_options(parser, section_format)

    assert config == OrderedDict(
        (
            ('foo', string.punctuation),
        )
    )
示例#2
0
def test_parse_section_options_for_missing_section_should_return_empty_dict():
    parser = flexmock()
    parser.should_receive('get').never()
    parser.should_receive('getint').never()
    parser.should_receive('has_option').with_args('section', 'foo').and_return(False)
    parser.should_receive('has_option').with_args('section', 'bar').and_return(False)

    section_format = module.Section_format(
        'section',
        (
            module.Config_option('foo', str, required=False),
            module.Config_option('bar', int, required=False),
        ),
    )

    config = module.parse_section_options(parser, section_format)

    assert config == OrderedDict()
示例#3
0
def test_parse_section_options_should_return_section_options():
    parser = flexmock()
    parser.should_receive('get').with_args('section', 'foo').and_return('value')
    parser.should_receive('getint').with_args('section', 'bar').and_return(1)
    parser.should_receive('has_option').with_args('section', 'foo').and_return(True)
    parser.should_receive('has_option').with_args('section', 'bar').and_return(True)

    section_format = module.Section_format(
        'section',
        (
            module.Config_option('foo', str, required=True),
            module.Config_option('bar', int, required=True),
        ),
    )

    config = module.parse_section_options(parser, section_format)

    assert config == OrderedDict(
        (
            ('foo', 'value'),
            ('bar', 1),
        )
    )
示例#4
0
def test_parse_section_options_should_return_section_options():
    parser = flexmock()
    parser.should_receive('get').with_args('section',
                                           'foo').and_return('value')
    parser.should_receive('getint').with_args('section', 'bar').and_return(1)
    parser.should_receive('has_option').with_args('section',
                                                  'foo').and_return(True)
    parser.should_receive('has_option').with_args('section',
                                                  'bar').and_return(True)

    section_format = module.Section_format(
        'section',
        (
            module.Config_option('foo', str, required=True),
            module.Config_option('bar', int, required=True),
        ),
    )

    config = module.parse_section_options(parser, section_format)

    assert config == OrderedDict((
        ('foo', 'value'),
        ('bar', 1),
    ))