Esempio n. 1
0
def test_config_write_read():
    fd, fname = tempfile.mkstemp()
    with os.fdopen(fd, 'w') as f:
        print('[MySection]', file=f)
        print('a=4', file=f)
        print('[OtherSection]', file=f)
        print('a=2', file=f)
        print('b=wefa feaf', file=f)
        print('c=wefa=feaf', file=f)

    cfg = Config(fname)
    os.remove(fname)

    my = cfg.section('MySection')
    other = cfg.section('OtherSection')
    assert_raises(KeyError, cfg.section,
                  'NonExistantSection')
    assert_true(type(my) is dict, "section is not a dictionary")
    assert_true('a' in my, "Value in section")
    assert_equals(
        my['a'], '4', "latest value does not overwrite earlier values")
    assert_equals(other['a'], '2', "value not contained to section")
    assert_equals(other['b'], 'wefa feaf', "spaces allowed")
    assert_equals(other['c'], 'wefa=feaf', "equals-sign allowed")
Esempio n. 2
0
def test_empty_config():
    cfg = Config(from_file=False)
    assert_raises(KeyError, cfg.section, 'notexist')
    cfg.add_section('my', {'a': 'b'})
    assert_equals(cfg.section('my')['a'], 'b')