예제 #1
0
def test_get_bool():
    config = Config()
    config.set('a', '')
    config.set('b', '123')
    config.set('c', '0')
    config.set('d', 'on')
    config.set('e', 'False')
    config.set('g', 'OFF')
    config.set('n', 'hello')
    assert config.bool('a') is False
    assert config.bool('b') is True
    assert config.bool('c') is False
    assert config.bool('d') is True
    assert config.bool('e') is False
    assert config.bool('g') is False
    assert config.bool('n') is True
예제 #2
0
def test_config_in_files():
    config = Config()
    assert config.list_config == ['first', 'second', 'third']
    assert config.dict('dict_config') == {
        'key1': 'value1',
        'key2': 'value2',
        'key3': 'value3'
    }
    assert config.str('dict_config.key1') == 'value1'
    with pytest.raises(KeyError):
        a = config['unknown']

    assert config.get('bool_prop') is True
    assert config.bool('bool_prop') is True
    assert config.bool('false_prop') is False
    assert config.str('logger.mode') == 'DEBUG'
예제 #3
0
def test_cast():
    config = Config()
    config.set('1', 123)
    assert config.str('1') == '123'
    config.set('a', 123)
    assert config.bool('a') is True
    config.set('a', False)
    assert config.bool('a') is False
    config.set('a', {1: 2})
    assert config.dict('a') == {1: 2}
    config.set('a', 'asdfs')
    assert config.dict('a') is None
    config.set('a', '[[[')
    assert config.list('a') is None
    config.set('a', [1, 2, 3])
    assert config.list('a') == [1, 2, 3]
    config.set('a', '')
    assert config.list('a') == []
    config.set('a', '{}')
    assert config.dict('a') == {}
    config.set('', '')
예제 #4
0
def test_ini_config():
    config = Config()
    assert config.get('general.value') == 34
    with pytest.raises(KeyError):
        config.get('asdf', raise_absent=True)

    with pytest.raises(KeyError):
        a = config.asdffdsa
    assert config.bool('section_a.bool_val') is False
    assert config.float('section_a.pi_val') == 3.14
    assert 'Port' in config.get('topsecret.server.com')
    assert config.get('topsecret.server.com')['Port'] == 50022
    assert config.get('bitbucket.org')['CompressionLevel'] == 9
    with pytest.raises(KeyError):
        var = config.get('bitbucket.org').unknown
예제 #5
0
파일: main.py 프로젝트: fivol/bestconfig
"""
Точка входа в модуль app
"""

from bestconfig import Config

config = Config('../dev.env', 'app.yaml')

if __name__ == '__main__':
    authorized_user_limit = config.int('limits.authorized.messages_per_second')

    DEBUG = config.bool('DEBUG')

    if DEBUG:
        print('RUN IN DEBUG MODE')
    else:
        print('RUN IN PRODUCTION MODE')