def test_parse_invalid_script(self): script = "Python cannot evaluate this string" p = PythonParams(script) def resolver(stack, key): return True with self.assertRaises(Exception): p.parse(resolver)
def test_parse_resolution_error(self): script = """{ 'Foo': 'Bar', 'Output': GetOutput('stack', 'Output'), }""" p = PythonParams(script) def resolver(stack, key): raise ResolutionError(stack, key, "error") with self.assertRaises(Exception): p.parse(resolver)
def test_supports_source(self): self.assertFalse(PythonParams.supports_source( ParameterArgument( kind='cli', value='ParameterKey=Foo,ParameterValue=file://Bar.py' ) )) self.assertFalse(PythonParams.supports_source( ParameterArgument( kind='file', value='/path/to/params.json' ) )) self.assertTrue(PythonParams.supports_source( ParameterArgument( kind='file', value='/path/to/params.py' ) ))
def test_parse(self): script = """{ 'Foo': 'Bar', 'Output': GetOutput('stack', 'Output'), 'Complex': str('foo' + GetOutput('stack', 'key')), }""" p = PythonParams(script) # Stub a resolver outputs = {'stack': {'Output': '42', 'key': 'bar'}} def resolver(stack, key): return outputs[stack][key] params = p.parse(resolver) self.assertEqual(params['Foo'], 'Bar') self.assertEqual(params['Output'], '42') self.assertEqual(params['Complex'], 'foobar')