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")
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
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
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()
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
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 == {}
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
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()
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