Browse Source

ConfigParser exeption message should be returned

When we fail to parse config file it would be good to know why instead
of having a generic message. When we print the exception, the message is
pretty clear.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1950544
Change-Id: I59ebd9e52b6fb6ab53ec9e53529d2feadc9e745e
changes/19/788119/5
David Vallee Delisle 3 months ago
parent
commit
a38d34dd82
  1. 6
      validations_common/library/validations_read_ini.py
  2. 7
      validations_common/tests/library/test_validations_read_ini.py

6
validations_common/library/validations_read_ini.py

@ -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)

7
validations_common/tests/library/test_validations_read_ini.py

@ -82,8 +82,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):

Loading…
Cancel
Save