From 54b59a6928c65f5dd715dcdb15404cd850c036da Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Mon, 27 Apr 2020 13:29:07 -0500 Subject: [PATCH] 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 --- reno/config.py | 3 ++- reno/tests/test_config.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/reno/config.py b/reno/config.py index fe32c19..7a8d03b 100644 --- a/reno/config.py +++ b/reno/config.py @@ -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 diff --git a/reno/tests/test_config.py b/reno/tests/test_config.py index 38e9635..090084f 100644 --- a/reno/tests/test_config.py +++ b/reno/tests/test_config.py @@ -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)