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

Unified Diff: third_party/recipe_engine/unittests/properties_test.py

Issue 1347263002: Revert of Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/recipe_engine/unittests/field_composer_test.py ('k') | third_party/recipe_engine/util.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/recipe_engine/unittests/properties_test.py
diff --git a/third_party/recipe_engine/unittests/properties_test.py b/third_party/recipe_engine/unittests/properties_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..b62af042e07dd96c015cf599910a557fde42ceb0
--- /dev/null
+++ b/third_party/recipe_engine/unittests/properties_test.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(
+ os.path.abspath(__file__)))))
+
+from recipe_engine import loader, recipe_api, config
+
+class TestProperties(unittest.TestCase):
+ def _makeProp(self, *args, **kwargs):
+ return recipe_api.Property(*args, **kwargs)
+
+ def testDefault(self):
+ """Tests the default option of properties."""
+ for default in (1, object(), "test", None):
+ prop = self._makeProp(default=default)
+ self.assertEqual(default, prop.interpret(recipe_api.Property.sentinel))
+
+ def testRequired(self):
+ """Tests that a required property errors when not provided."""
+ prop = self._makeProp()
+ with self.assertRaises(ValueError):
+ prop.interpret(recipe_api.Property.sentinel)
+
+ def testTypeSingle(self):
+ """Tests a simple typed property."""
+ prop = self._makeProp(kind=bool)
+ with self.assertRaises(TypeError):
+ prop.interpret(1)
+
+ self.assertEqual(True, prop.interpret(True))
+
+ def testTypeFancy(self):
+ """Tests a config style type property."""
+ prop = self._makeProp(kind=config.List(int))
+ for value in (1, "hi", [3, "test"]):
+ with self.assertRaises(TypeError):
+ prop.interpret(value)
+
+ self.assertEqual([2, 3], prop.interpret([2, 3]))
+
+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 testInvokeFuncSimple(self):
+ """Simple test of invoke."""
+ def func():
+ pass
+
+ self.assertEqual(self.invoke(func, {}, {}), None)
+
+ def testInvokeFuncComplex(self):
+ """Tests invoke with two different properties."""
+ def func(a, b):
+ return a
+
+ prop_defs = {
+ 'a': recipe_api.Property(),
+ 'b': recipe_api.Property(),
+ }
+
+ props = {
+ 'a': 1,
+ 'b': 2,
+ }
+ self.assertEqual(1, self.invoke(func, props, prop_defs))
+
+ def testInvokeClass(self):
+ """Tests invoking a class."""
+ class test(object):
+ def __init__(self, a, b):
+ self.answer = a
+
+ prop_defs = {
+ 'a': recipe_api.Property(),
+ 'b': recipe_api.Property(),
+ }
+
+ props = {
+ 'a': 1,
+ 'b': 2,
+ }
+ self.assertEqual(1, self.invoke(test, props, prop_defs).answer)
+
+ def testMissingProperty(self):
+ """Tests that invoke raises an error when missing a property."""
+ def func(a):
+ return a
+
+ with self.assertRaises(recipe_api.UndefinedPropertyException):
+ self.invoke(func, {}, {})
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « third_party/recipe_engine/unittests/field_composer_test.py ('k') | third_party/recipe_engine/util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698