| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import test_env | 10 import test_env |
| 11 | 11 |
| 12 from recipe_engine import loader, recipe_api, config | 12 from recipe_engine import config, loader, recipe_api, run |
| 13 import mock | 13 import mock |
| 14 | 14 |
| 15 | 15 |
| 16 class TestRecipeScript(unittest.TestCase): | 16 class TestRecipeScript(unittest.TestCase): |
| 17 def testReturnSchemaHasValidClass(self): | 17 def testReturnSchemaHasValidClass(self): |
| 18 with self.assertRaises(ValueError): | 18 with self.assertRaises(ValueError): |
| 19 script = loader.RecipeScript({'RETURN_SCHEMA': 3}, 'test_script') | 19 script = loader.RecipeScript({'RETURN_SCHEMA': 3}, 'test_script') |
| 20 | 20 |
| 21 def testRunChecksReturnType(self): | 21 def testRunChecksReturnType(self): |
| 22 sentinel = object() | 22 sentinel = object() |
| 23 mocked_return = object() | 23 mocked_return = object() |
| 24 class FakeReturn(object): | 24 class FakeReturn(object): |
| 25 def as_jsonish(_self, hidden=sentinel): | 25 def as_jsonish(_self, hidden=sentinel): |
| 26 self.assertEqual(True, hidden) | 26 self.assertEqual(True, hidden) |
| 27 | 27 |
| 28 return mocked_return | 28 return mocked_return |
| 29 | 29 |
| 30 script = loader.RecipeScript({ | 30 script = loader.RecipeScript({ |
| 31 'RETURN_SCHEMA': config.ConfigGroupSchema(a=config.Single(int)), | 31 'RETURN_SCHEMA': config.ConfigGroupSchema(a=config.Single(int)), |
| 32 'RunSteps': None, | 32 'RunSteps': None, |
| 33 }, 'test_script') | 33 }, 'test_script') |
| 34 loader.invoke_with_properties = lambda *args, **kwargs: FakeReturn() | 34 loader.invoke_with_properties = lambda *args, **kwargs: FakeReturn() |
| 35 | 35 |
| 36 self.assertEqual(mocked_return, script.run(None, None)) | 36 rt = run.Runtime({}) |
| 37 self.assertEqual(mocked_return, script.run(None, rt)) |
| 37 | 38 |
| 38 def make_prop(**kwargs): | 39 def make_prop(**kwargs): |
| 39 name = kwargs.pop('name', "dumb_name") | 40 name = kwargs.pop('name', "dumb_name") |
| 40 return recipe_api.Property(**kwargs).bind(name, 'test', 'properties_test') | 41 return recipe_api.Property(**kwargs).bind(name, 'test', 'properties_test') |
| 41 | 42 |
| 42 | 43 |
| 43 class TestInvoke(unittest.TestCase): | 44 class TestInvoke(unittest.TestCase): |
| 44 def invoke(self, callable, all_properties, prop_defs, arg_names, **kwargs): | 45 def invoke(self, callable, all_properties, prop_defs, arg_names, **kwargs): |
| 45 return loader._invoke_with_properties( | 46 return loader._invoke_with_properties( |
| 46 callable, all_properties, prop_defs, arg_names, **kwargs) | 47 callable, all_properties, prop_defs, arg_names, **kwargs) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 with mock.patch( | 135 with mock.patch( |
| 135 'recipe_engine.loader._invoke_with_properties') as mocked_invoke: | 136 'recipe_engine.loader._invoke_with_properties') as mocked_invoke: |
| 136 loader.invoke_with_properties(TestClass, None, None) | 137 loader.invoke_with_properties(TestClass, None, None) |
| 137 args, _ = mocked_invoke.call_args | 138 args, _ = mocked_invoke.call_args |
| 138 self.assertTrue(['api', 'foo', 'bar'] in args) | 139 self.assertTrue(['api', 'foo', 'bar'] in args) |
| 139 | 140 |
| 140 | 141 |
| 141 if __name__ == '__main__': | 142 if __name__ == '__main__': |
| 142 unittest.main() | 143 unittest.main() |
| OLD | NEW |