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

Unified Diff: recipe_engine/unittests/loader_test.py

Issue 1421843006: Add simple depends_on API. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Fix small broken tests, add invoke tests, respond to nits. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: recipe_engine/unittests/loader_test.py
diff --git a/recipe_engine/unittests/loader_test.py b/recipe_engine/unittests/loader_test.py
index 70379fddf58762b399f44ab115018aa987982012..b4138c523e44baee7533eabec7f0e4a9f175771d 100755
--- a/recipe_engine/unittests/loader_test.py
+++ b/recipe_engine/unittests/loader_test.py
@@ -46,16 +46,16 @@ def make_prop(**kwargs):
class TestInvoke(unittest.TestCase):
- def invoke(self, callable, all_properties, prop_defs, **kwargs):
- return loader.invoke_with_properties(
- callable, all_properties, prop_defs, **kwargs)
+ def invoke(self, callable, all_properties, prop_defs, arg_names, **kwargs):
+ return loader._invoke_with_properties(
+ callable, all_properties, prop_defs, arg_names, **kwargs)
def testInvokeFuncSimple(self):
"""Simple test of invoke."""
def func():
pass
- self.assertEqual(self.invoke(func, {}, {}), None)
+ self.assertEqual(self.invoke(func, {}, {}, []), None)
def testInvokeFuncComplex(self):
"""Tests invoke with two different properties."""
@@ -71,7 +71,7 @@ class TestInvoke(unittest.TestCase):
'a': 1,
'b': 2,
}
- self.assertEqual(1, self.invoke(func, props, prop_defs))
+ self.assertEqual(1, self.invoke(func, props, prop_defs, ['a', 'b']))
def testInvokeParamName(self):
"""Tests invoke with two different properties."""
@@ -85,7 +85,7 @@ class TestInvoke(unittest.TestCase):
props = {
'b': 2,
}
- self.assertEqual(2, self.invoke(func, props, prop_defs))
+ self.assertEqual(2, self.invoke(func, props, prop_defs, ['a']))
def testInvokeClass(self):
"""Tests invoking a class."""
@@ -102,7 +102,7 @@ class TestInvoke(unittest.TestCase):
'a': 1,
'b': 2,
}
- self.assertEqual(1, self.invoke(test, props, prop_defs).answer)
+ self.assertEqual(1, self.invoke(test, props, prop_defs, ['a', 'b']).answer)
def testMissingProperty(self):
"""Tests that invoke raises an error when missing a property."""
@@ -110,7 +110,7 @@ class TestInvoke(unittest.TestCase):
return a
with self.assertRaises(recipe_api.UndefinedPropertyException):
- self.invoke(func, {}, {})
+ self.invoke(func, {}, {}, ['a'])
def testMustBeBound(self):
"""Tests that calling invoke with a non BoundProperty fails."""
@@ -119,7 +119,41 @@ class TestInvoke(unittest.TestCase):
}
with self.assertRaises(ValueError):
- self.invoke(None, None, prop_defs)
+ self.invoke(None, None, prop_defs, ['a'])
+
+ def testInvokeArgNamesFunc(self):
+ def test_function(a, b):
+ return a
+
+ self._old_inner_invoke = loader._invoke_with_properties
+ def mock_inner_invoke(_, __, ___, names):
+ return names
+ loader._invoke_with_properties = mock_inner_invoke
luqui 2015/11/20 01:07:02 Doesn't mock provide a cleaner way of doing things
iannucci 2015/11/20 02:00:19 (yes it does)
martiniss 2015/11/23 22:05:07 much wow. Had to fix it, since we don't actually
+
+ try:
+ self.assertEqual(
+ ['a', 'b'],
+ loader.invoke_with_properties(test_function, None, None))
+ finally:
+ loader._invoke_with_properties = self._old_inner_invoke
+
+ def testInvokeArgNamesClass(self):
+ class TestClass(object):
+ def __init__(self, api, foo, bar):
+ pass
+
+ self._old_inner_invoke = loader._invoke_with_properties
+ def mock_inner_invoke(_, __, ___, names):
+ return names
+
+ loader._invoke_with_properties = mock_inner_invoke
+
+ try:
+ self.assertEqual(
+ ['api', 'foo', 'bar'],
+ loader.invoke_with_properties(TestClass, None, None))
+ finally:
+ loader._invoke_with_properties = self._old_inner_invoke
if __name__ == '__main__':
unittest.main()
« recipe_engine/run.py ('K') | « recipe_engine/simulation_test.py ('k') | recipes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698