Sync yamlutils with solumclient changes for empty list

Change-Id: I27dfabe396ee7dc68a38d0c294c45c1f8696e5dc
This commit is contained in:
Pierre Padrixe 2014-06-24 11:49:46 +02:00
parent 5653efe454
commit 21b8fe01de
2 changed files with 7 additions and 3 deletions

View File

@ -34,9 +34,9 @@ def load(s):
msg += ' Error position: (%s:%s)' % (exc.problem_mark.line + 1,
exc.problem_mark.column + 1)
raise ValueError(msg)
if not isinstance(yml_dict, dict):
raise ValueError('The source is not a YAML mapping.')
if len(yml_dict) < 1:
if not isinstance(yml_dict, dict) and not isinstance(yml_dict, list):
raise ValueError('The source is not a YAML mapping or list.')
if isinstance(yml_dict, dict) and len(yml_dict) < 1:
raise ValueError('Could not find any element in your YAML mapping.')
return yml_dict

View File

@ -28,6 +28,10 @@ class TestYamlUtils(base.BaseTestCase):
def test_load_empty_yaml(self):
self.assertRaises(ValueError, yamlutils.load, '{}')
def test_load_empty_list(self):
yml_dict = yamlutils.load('[]')
self.assertEqual(yml_dict, [])
def test_load_invalid_yaml_syntax(self):
self.assertRaises(ValueError, yamlutils.load, "}invalid: y'm'l3!")