Exemplo n.º 1
0
def test_config_get_value_priority():
    try:
        config = Config()
        _config = config.get_config(section='logger')
        assert _config == {
            'name':
            'default-logger',
            'log_dir':
            'logs',
            'config_path':
            os.path.join(config.get_default_config_dir(), 'logging.json')
        }
        default_value = Config.collect_value(section='logger',
                                             key='name',
                                             config=dict())
        assert default_value == 'default-logger'
        name = Config.collect_value(section='logger',
                                    key='name',
                                    config=_config)
        assert name == 'default-logger'
        os.environ['CODEPACK_LOGGER_NAME'] = 'test-logger'
        name = Config.collect_value(section='logger',
                                    key='name',
                                    config=_config)
        assert name == 'test-logger'
        os.environ.pop('CODEPACK_LOGGER_NAME')
        os.environ['CODEPACK_CONFIG_PATH'] = 'config/test.ini'
        os.environ['CODEPACK_CONFIG_DIR'] = 'config'
        config = Config()
        _config = config.get_config(section='logger')
        assert _config == {
            'name': 'default-logger',
            'config_path': os.path.join('config', 'logging.json'),
            'log_dir': 'logs'
        }
        name = Config.collect_value(section='logger',
                                    key='name',
                                    config=_config)
        assert name == 'default-logger'
        os.environ['CODEPACK_LOGGER_NAME'] = 'test-logger'
        name = Config.collect_value(section='logger',
                                    key='name',
                                    config=_config)
        assert name == 'test-logger'
    finally:
        os.environ.pop('CODEPACK_LOGGER_NAME', None)
        os.environ.pop('CODEPACK_CONFIG_PATH', None)
        os.environ.pop('CODEPACK_CONFIG_DIR', None)
Exemplo n.º 2
0
def test_config_dir():
    path = Config.collect_value(section='?',
                                key='path',
                                config={'path': 'config/test.ini'})
    assert path == 'config/test.ini'
    with pytest.raises(AssertionError):
        Config.collect_value(section='conn',
                             key='path',
                             config={'path': 'test.ini'})
    try:
        os.environ['CODEPACK_CONFIG_DIR'] = 'config'
        path = Config.collect_value(section='conn',
                                    key='path',
                                    config={'path': 'test.ini'})
        assert path == os.path.join('config', 'test.ini')
    finally:
        os.environ.pop('CODEPACK_CONFIG_DIR', None)