Browse Source

Merge "ConfigParser exeption message should be returned"

changes/18/790918/1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
328416ee61
2 changed files with 9 additions and 4 deletions
  1. +4
    -2
      validations_common/library/validations_read_ini.py
  2. +5
    -2
      validations_common/tests/library/test_validations_read_ini.py

+ 4
- 2
validations_common/library/validations_read_ini.py 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)


+ 5
- 2
validations_common/tests/library/test_validations_read_ini.py 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):


Loading…
Cancel
Save