def test_error_on_invalid_data(temp_dir, invalid_data): with pytest.raises(ConfigLoadException): Config(from_string=invalid_data) file_name = write_file(invalid_data, root_dir=temp_dir) with pytest.raises(ConfigLoadException): Config(from_file=file_name)
def test_error_on_including_invalid_data(temp_dir, invalid_data): write_file(invalid_data, file_name='invalid.yml', root_dir=temp_dir) with pytest.raises(ConfigLoadException): Config(from_string=invalid_data) file_name = write_file('include:\n- invalid.yml', root_dir=temp_dir) with pytest.raises(ConfigLoadFormatException): Config(from_file=file_name)
def test_including_missing_file(temp_dir): file_name = write_file('include_optional:\n- {}'.format(MISSING_FILE_NAME), root_dir=temp_dir) config = Config(from_file=file_name) assert config == {} assert config.sources == "'{}'".format(file_name)
def test_including_files(temp_dir): file_data = YAML_LOOKUP_FILE_DATA write_file(file_data, file_name=YAML_LOOKUP_FILE_NAME, root_dir=temp_dir, dump_yaml=True) for include_str in ( 'include:\n- {}\n'.format(YAML_LOOKUP_FILE_NAME), 'include_optional:\n- {}\n'.format(YAML_LOOKUP_FILE_NAME)): config = Config(from_string=include_str) assert len(config) == len(file_data.keys()) assert config.sources == ConfigStringLoader.CONFIG_NAME for key, val in file_data.iteritems(): assert config[key] == val file_name = write_file(include_str, root_dir=temp_dir) config = Config(from_file=file_name) assert len(config) == len(file_data.keys()) assert config.sources == "'{}'".format(file_name) for key, val in file_data.iteritems(): assert config[key] == val
def test_error_on_missing_file(): with pytest.raises(ConfigLoadException): Config(from_file=MISSING_FILE_NAME)
def test_error_on_invalid_include(temp_dir, test_data): file_name = write_file(test_data, root_dir=temp_dir) with pytest.raises(ConfigException): Config(from_file=file_name)