Merge "Fixes environment file using correct YAML format"
This commit is contained in:
@@ -26,7 +26,7 @@ def parse(env_str):
|
||||
'''Takes a string and returns a dict containing the parsed structure.
|
||||
|
||||
This includes determination of whether the string is using the
|
||||
JSON or YAML format.
|
||||
YAML format.
|
||||
'''
|
||||
try:
|
||||
env = yaml.load(env_str, Loader=yaml_loader)
|
||||
@@ -35,6 +35,9 @@ def parse(env_str):
|
||||
else:
|
||||
if env is None:
|
||||
env = {}
|
||||
elif not isinstance(env, dict):
|
||||
raise ValueError('The environment is not a valid '
|
||||
'YAML mapping data type.')
|
||||
|
||||
for param in env:
|
||||
if param not in SECTIONS:
|
||||
|
||||
@@ -49,6 +49,18 @@ parameters: }
|
||||
'''
|
||||
self.assertRaises(ValueError, environment_format.parse, env)
|
||||
|
||||
def test_parse_string_environment(self):
|
||||
env = 'just string'
|
||||
expect = 'The environment is not a valid YAML mapping data type.'
|
||||
msg = self.assertRaises(ValueError, environment_format.parse, env)
|
||||
self.assertIn(expect, msg)
|
||||
|
||||
def test_parse_document(self):
|
||||
env = '["foo" , "bar"]'
|
||||
expect = 'The environment is not a valid YAML mapping data type.'
|
||||
msg = self.assertRaises(ValueError, environment_format.parse, env)
|
||||
self.assertIn(expect, msg)
|
||||
|
||||
|
||||
class YamlParseExceptions(testtools.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user