Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: recipe_engine/unittests/loader_test.py

Issue 2864803003: Minor loader improvements. (Closed)
Patch Set: fix tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_engine/loader.py ('k') | unittests/errors_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 unittest 6 import unittest
7 7
8 import test_env 8 import test_env
9 9
10 from recipe_engine import loader, recipe_api, config 10 from recipe_engine import loader, recipe_api, config
11 import mock 11 import mock
12 12
13 13
14 class TestRecipeScript(unittest.TestCase): 14 class TestRecipeScript(unittest.TestCase):
15 def testReturnSchemaHasValidClass(self): 15 def testReturnSchemaHasValidClass(self):
16 with self.assertRaises(ValueError): 16 with self.assertRaises(loader.MalformedRecipeError):
17 loader.RecipeScript('fake_recipe', 17 loader.RecipeScript('fake_recipe', {
18 {'RETURN_SCHEMA': 3}, 'fake_package', 'some/path') 18 'GenTests': lambda api: None,
19 'RunSteps': lambda api: None,
20 'RETURN_SCHEMA': 3,
21 }, 'fake_package', 'some/path')
19 22
20 def testRunChecksReturnType(self): 23 def testRunChecksReturnType(self):
21 sentinel = object() 24 sentinel = object()
22 mocked_return = object() 25 mocked_return = object()
23 class FakeReturn(object): 26 class FakeReturn(object):
24 def as_jsonish(_self, hidden=sentinel): 27 def as_jsonish(_self, hidden=sentinel):
25 self.assertEqual(True, hidden) 28 self.assertEqual(True, hidden)
26 29
27 return mocked_return 30 return mocked_return
28 31
29 script = loader.RecipeScript( 32 script = loader.RecipeScript(
30 'fake_recipe', { 33 'fake_recipe', {
31 'RETURN_SCHEMA': config.ConfigGroupSchema(a=config.Single(int)), 34 'RETURN_SCHEMA': config.ConfigGroupSchema(a=config.Single(int)),
32 'RunSteps': None, 35 'RunSteps': lambda api: None,
36 'GenTests': lambda api: None,
33 }, 'fake_package', 'some/path') 37 }, 'fake_package', 'some/path')
34 loader.invoke_with_properties = lambda *args, **kwargs: FakeReturn() 38 loader.invoke_with_properties = lambda *args, **kwargs: FakeReturn()
35 39
36 self.assertEqual(mocked_return, script.run(None, None)) 40 self.assertEqual(mocked_return, script.run(None, None))
37 41
38 def make_prop(**kwargs): 42 def make_prop(**kwargs):
39 name = kwargs.pop('name', "dumb_name") 43 name = kwargs.pop('name', "dumb_name")
40 return recipe_api.Property(**kwargs).bind( 44 return recipe_api.Property(**kwargs).bind(
41 name, recipe_api.BoundProperty.RECIPE_PROPERTY, 45 name, recipe_api.BoundProperty.RECIPE_PROPERTY,
42 'fake_package::fake_recipe') 46 'fake_package::fake_recipe')
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 139
136 with mock.patch( 140 with mock.patch(
137 'recipe_engine.loader._invoke_with_properties') as mocked_invoke: 141 'recipe_engine.loader._invoke_with_properties') as mocked_invoke:
138 loader.invoke_with_properties(TestClass, None, None) 142 loader.invoke_with_properties(TestClass, None, None)
139 args, _ = mocked_invoke.call_args 143 args, _ = mocked_invoke.call_args
140 self.assertTrue(['api', 'foo', 'bar'] in args) 144 self.assertTrue(['api', 'foo', 'bar'] in args)
141 145
142 146
143 if __name__ == '__main__': 147 if __name__ == '__main__':
144 unittest.main() 148 unittest.main()
OLDNEW
« no previous file with comments | « recipe_engine/loader.py ('k') | unittests/errors_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698