Merge "Fix parsing bug when config file is empty."

This commit is contained in:
Jenkins 2017-07-13 11:41:50 +00:00 committed by Gerrit Code Review
commit f62fd2b499
2 changed files with 6 additions and 1 deletions

View File

@ -350,7 +350,7 @@ def parse_file_contents(data):
# For backwards-compatibility, convert yaml error to ValueError,
# which is what JSON loader raised.
raise ValueError(six.text_type(e))
return parsed
return parsed or {}
class Rules(dict):

View File

@ -129,6 +129,11 @@ class RulesTestCase(test_base.BaseTestCase):
self.assertRaises(ValueError, policy.Rules.load, exemplar,
'default')
@mock.patch.object(_parser, 'parse_rule', lambda x: x)
def test_load_empty_data(self):
result = policy.Rules.load('', 'default')
self.assertEqual(result, {})
@mock.patch.object(_parser, 'parse_rule', lambda x: x)
def test_load_yaml(self):
# Test that simplified YAML can be used with load().