Merge "ConfigParser exeption message should be returned"

This commit is contained in:
Zuul 2021-05-11 18:44:41 +00:00 committed by Gerrit Code Review
commit 328416ee61
2 changed files with 9 additions and 4 deletions

View File

@ -60,8 +60,10 @@ def get_result(path, section, key, default=None):
try:
config.read(path)
except (OSError, ConfigParser.ParsingError):
msg = "The file '{}' is not in a valid INI format.".format(path)
except (OSError, ConfigParser.ParsingError) as exc_msg:
msg = "The file '{}' is not in a valid INI format: {}".format(
path, exc_msg
)
ret = ReturnValue.INVALID_FORMAT
return (ret, msg, value)

View File

@ -88,8 +88,11 @@ class TestValidationsReadIni(base.TestCase):
tmpfile.close()
self.assertEqual(validation.ReturnValue.INVALID_FORMAT, ret)
self.assertEqual("The file '{}' is not in a valid INI format.".format(
tmp_name), msg)
asserted = ("The file '{path}' is not in a valid INI format: File "
"contains no section headers.\nfile: '{path}', line: 2\n"
"'[DEFAULT#\\n\'").format(path=tmp_name)
self.assertEqual(asserted, msg)
self.assertIsNone(value)
def test_get_result_key_not_found(self):