Пример #1
0
def test_get_configparser_no_conf_d_dir(m, test_conf_dir):
    conf_filename = os.path.join(test_conf_dir, 'example2.conf')
    parser = get_configparser(conf_filename)
    assert isinstance(parser, configparser.RawConfigParser)
    assert parser.get('DEFAULT', 'test_option') == 'baz'
    expected = [
        mock.call.info("Found config '%s'", conf_filename),
    ]
    assert m.mock_calls == expected
Пример #2
0
def test_get_configparser_warn(m, test_conf_dir):
    conf_filename = os.path.join(test_conf_dir, 'example.conf')
    parser = get_configparser(conf_filename)
    assert isinstance(parser, configparser.RawConfigParser)
    assert parser.get('DEFAULT', 'test_option') == 'baz'
    assert m.mock_calls == [
        mock.call.info("Found config '%s'", conf_filename),
        mock.call.info("Found config '%s'", 'abc'),
        mock.call.warning("Error while parsing config '%s'", 'abc'),
    ]
Пример #3
0
def test_get_configparser(m, test_conf_dir):
    conf_filename = os.path.join(test_conf_dir, 'example.conf')
    conf_d_dir = os.path.join(test_conf_dir, 'example.conf.d')
    parser = get_configparser(conf_filename)
    assert isinstance(parser, configparser.RawConfigParser)
    assert parser.get('DEFAULT', 'test_option') == 'bar'
    assert m.mock_calls == [
        mock.call.info("Found config '%s'", conf_filename),
        mock.call.info("Found config '%s'",
                       os.path.join(conf_d_dir, '10-app.conf')),
        mock.call.info("Found config '%s'",
                       os.path.join(conf_d_dir, '20-database.conf')),
    ]
Пример #4
0
def test_get_configparser_config_does_not_exist(test_conf_dir):
    conf_filename = os.path.join(test_conf_dir, 'example_not_exists.conf')
    with pytest.raises(ValueError) as e:
        get_configparser(conf_filename)
    assert 'is not a file' in str(e)
Пример #5
0
def test_get_configparser_empty_filename():
    with pytest.raises(ImproperlyConfiguredError) as exc_info:
        get_configparser('')
    assert "Configuration file is not defined" in str(exc_info.value)