Пример #1
0
def test_config_reading_default_file():
    """Test that the Config will work with a default file."""
    config = Config(APP_NAME,
                    APP_AUTHOR,
                    'test_config',
                    default=os.path.join(TEST_DATA_DIR, 'configrc'))
    config.read_default_config()
    assert config.data == DEFAULT_CONFIG
Пример #2
0
def test_config_reading_configspec():
    """Test that the Config default file will work with a configspec."""
    config = Config(APP_NAME,
                    APP_AUTHOR,
                    'test_config',
                    validate=True,
                    default=os.path.join(TEST_DATA_DIR, 'configspecrc'))
    config.read_default_config()
    assert config.data == DEFAULT_VALID_CONFIG
Пример #3
0
def test_config_reading_raise_errors():
    """Test that instantiating Config will raise errors when appropriate."""
    with pytest.raises(ValueError):
        Config(APP_NAME, APP_AUTHOR, "test_config", write_default=True)

    with pytest.raises(ValueError):
        Config(APP_NAME, APP_AUTHOR, "test_config", validate=True)

    with pytest.raises(TypeError):
        Config(APP_NAME, APP_AUTHOR, "test_config", default=b"test")
Пример #4
0
def test_config_reading_configspec_with_error():
    """Test that reading an invalid configspec raises and exception."""
    with pytest.raises(DefaultConfigValidationError):
        config = Config(APP_NAME,
                        APP_AUTHOR,
                        'test_config',
                        validate=True,
                        default=os.path.join(TEST_DATA_DIR,
                                             'invalid_configspecrc'))
        config.read_default_config()
Пример #5
0
def _mocked_user_config(temp_dir, *args, **kwargs):
    config = Config(*args, **kwargs)
    config.user_config_file = MagicMock(
        return_value=os.path.join(temp_dir, config.filename))
    return config
Пример #6
0
def test_config_reading_no_default():
    """Test that the Config constructor will work without any defaults."""
    config = Config(APP_NAME, APP_AUTHOR, "test_config")
    assert config.data == {}
Пример #7
0
def test_config_reading_default_dict():
    """Test that the Config constructor will read in defaults from a dict."""
    default = {"main": {"foo": "bar"}}
    config = Config(APP_NAME, APP_AUTHOR, "test_config", default=default)
    assert config.data == default
Пример #8
0
def test_config_user_file():
    """Test that the Config user_config_file is appropriate."""
    config = Config(APP_NAME, APP_AUTHOR, "test_config")
    assert get_user_config_dir(APP_NAME,
                               APP_AUTHOR) in config.user_config_file()
Пример #9
0
def test_config_reading_default_dict():
    """Test that the Config constructor will read in defaults from a dict."""
    default = {'main': {'foo': 'bar'}}
    config = Config(APP_NAME, APP_AUTHOR, 'test_config', default=default)
    assert config.data == default