Example #1
0
def test_config_wildcard():
    cf = Config('base', CONFIG)

    eq_(cf.get_wildcard('wild-*-*', ['a', 'b']), 'w.a.b')
    eq_(cf.get_wildcard('wild-*-*', ['a', 'x']), 'w.a')
    eq_(cf.get_wildcard('wild-*-*', ['q', 'b']), 'w2')
    eq_(cf.get_wildcard('missing-*-*', ['1', '2'], 'def'), 'def')
    assert_raises(NoOptionError, cf.get_wildcard, 'missing-*-*', ['1', '2'])
Example #2
0
def test_nofile():
    cf = Config('base', None, user_defs={'a': '1'})
    eq_(cf.sections(), ['base'])
    eq_(cf.get('a'), '1')

    cf = Config('base', None, user_defs={'a': '1'}, ignore_defs=True)
    eq_(cf.get('a', '2'), '2')
Example #3
0
def test_config_other():
    cf = Config('base', CONFIG)
    eq_(sorted(cf.sections()), ['base', 'other'])
    assert_true(cf.has_section('base'))
    assert_true(cf.has_section('other'))
    assert_false(cf.has_section('missing'))
    assert_false(cf.has_section('DEFAULT'))

    assert_false(cf.has_option('missing'))
    assert_true(cf.has_option('all'))
    assert_true(cf.has_option('foo'))

    cf2 = cf.clone('other')
    eq_(sorted(cf2.options()), [
        'all', 'config_dir', 'config_file', 'host_name', 'job_name',
        'service_name', 'test'
    ])
    eq_(len(cf2.items()), len(cf2.options()))
Example #4
0
def test_config_bool():
    cf = Config('base', CONFIG)
    eq_(cf.getboolean('bool-true1'), True)
    eq_(cf.getboolean('bool-true2'), True)
    eq_(cf.getboolean('missing', True), True)
    assert_raises(NoOptionError, cf.getboolean, 'missing')

    eq_(cf.getboolean('bool-false1'), False)
    eq_(cf.getboolean('bool-false2'), False)
    eq_(cf.getboolean('missing', False), False)
    assert_raises(NoOptionError, cf.getbool, 'missing')
Example #5
0
def test_config_default():
    cf = Config('base', CONFIG)
    eq_(cf.get('all'), 'yes')
Example #6
0
def test_config_bytes():
    cf = Config('base', CONFIG)
    eq_(cf.getbytes('bytes-val1'), 4)
    eq_(cf.getbytes('bytes-val2'), 2048)
    eq_(cf.getbytes('missing', '3k'), 3072)
    assert_raises(NoOptionError, cf.getbytes, 'missing')
Example #7
0
def test_config_file():
    cf = Config('base', CONFIG)
    eq_(cf.getfile('file-val1'), '-')
    eq_(cf.getfile('file-val2')[0], '/')
    eq_(cf.getfile('missing', 'qwe'), 'qwe')
    assert_raises(NoOptionError, cf.getfile, 'missing')
Example #8
0
def test_config_dict():
    cf = Config('base', CONFIG)
    eq_(cf.getdict('dict-val1'), {})
    eq_(cf.getdict('dict-val2'), {'a': '1', 'b': '2', 'z': 'z'})
    eq_(cf.getdict('missing', {'a': 1}), {'a': 1})
    assert_raises(NoOptionError, cf.getdict, 'missing')
Example #9
0
def test_config_list():
    cf = Config('base', CONFIG)
    eq_(cf.getlist('list-val1'), [])
    eq_(cf.getlist('list-val2'), ['a', '1', 'asd', 'ppp'])
    eq_(cf.getlist('missing', [1]), [1])
    assert_raises(NoOptionError, cf.getlist, 'missing')
Example #10
0
def test_config_float():
    cf = Config('base', CONFIG)
    eq_(cf.getfloat('float-val'), 2.0)
    eq_(cf.getfloat('missing', 3.0), 3.0)
    assert_raises(NoOptionError, cf.getfloat, 'missing')
Example #11
0
def test_config_int():
    cf = Config('base', CONFIG)
    eq_(cf.getint('foo'), 1)
    eq_(cf.getint('missing', 2), 2)
    assert_raises(NoOptionError, cf.getint, 'missing')
Example #12
0
def test_config_str():
    cf = Config('base', CONFIG)
    eq_(cf.get('foo'), '1')
    eq_(cf.get('missing', 'q'), 'q')
    assert_raises(NoOptionError, cf.get, 'missing')
Example #13
0
def test_vars():
    cf = Config('base', CONFIG)
    eq_(cf.get('vars1'), 'V2=V3=Q3')

    assert_raises(InterpolationError, cf.get, 'bad1')
Example #14
0
def test_override():
    cf = Config('base', CONFIG, override={'foo': 'overrided'})
    eq_(cf.get('foo'), 'overrided')