Handle empty config files
Current code was assuming if a reno.yaml file was found that it could load that file to read config options. While probably a safe assumption in the majority of cases, someone that isn't aware of this could modify their config file to remove settings, leaving an empty or comment-only file that when read does not actually load any yaml that can be used. This adds protection for that to make reno does not try to use an empty file. Change-Id: I0ae0bcc93a79bbf66735833b654964b494485ee1 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
parent
370f1a5c7b
commit
54b59a6928
|
@ -228,7 +228,8 @@ class Config(object):
|
|||
except IOError as err:
|
||||
self._report_failure_config_file(filename, err)
|
||||
else:
|
||||
self.override(**self._contents)
|
||||
if self._contents:
|
||||
self.override(**self._contents)
|
||||
|
||||
def _report_missing_config_files(self, filenames):
|
||||
# NOTE(dhellmann): This is extracted so we can mock it for
|
||||
|
|
|
@ -95,6 +95,14 @@ collapse_pre_releases: false
|
|||
config_path = self.tempdir.join('reno.yaml')
|
||||
self._test_load_file(config_path)
|
||||
|
||||
def test_load_file_empty(self):
|
||||
config_path = self.tempdir.join('reno.yaml')
|
||||
with open(config_path, 'w') as fd:
|
||||
fd.write('# Add reno config here')
|
||||
self.addCleanup(os.unlink, config_path)
|
||||
c = config.Config(self.tempdir.path)
|
||||
self.assertEqual(True, c.collapse_pre_releases)
|
||||
|
||||
def test_get_default(self):
|
||||
d = config.Config.get_default('notesdir')
|
||||
self.assertEqual('notes', d)
|
||||
|
|
Loading…
Reference in New Issue