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

Unified Diff: unittests/recipes_py_test.py

Issue 2237593002: Add support for operational arguments protobuf. (Closed) Base URL: https://github.com/luci/recipes-py@proto3-release
Patch Set: Comments, add list type, small changes. Created 4 years, 4 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
« recipes.py ('K') | « recipes.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: unittests/recipes_py_test.py
diff --git a/unittests/recipes_py_test.py b/unittests/recipes_py_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..eff5c4a06aec619bd4f4d4c1e217e8181fc41eb3
--- /dev/null
+++ b/unittests/recipes_py_test.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+# Copyright 2016 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+import base64
+import json
+import unittest
+
+import repo_test_util
+
+import recipes
+from recipe_engine import arguments_pb2
+from google.protobuf import json_format as jsonpb
+
+
+class TestOperationalArgs(unittest.TestCase):
+
+ def test_operational_arg_parsing(self):
+ # For convenience, we'll define the JSONPB data as a Python dict that we
+ # will then dump into JSON.
+ op_args = jsonpb.Parse(json.dumps({
+ 'properties': {'property': {
+ 'a': {'s': 'Hello'},
+ 'b': {'int': -12345},
+ 'c': {'uint': 12345},
+ 'd': {'d': 3.14159},
+ 'e': {'b': True},
+ 'f': {'data': base64.b64encode('\x60\x0d\xd0\x65')},
+ 'g': {'map': {
+ 'property': {
+ 'foo': {'s': 'FOO!'},
+ 'bar': {'map': {
+ 'property': {
+ 'baz': {'s': 'BAZ!'},
+ },
+ }},
+ }},
+ },
+ 'h': {'list': {
+ 'property': [
+ {'s': 'foo'},
+ {'s': 'bar'},
+ {'s': 'baz'},
+ ],
+ }},
+ }},
+ 'annotationFlags': {
+ 'emitTimestamp': True,
+ },
+ }), arguments_pb2.Arguments())
+
+ self.assertEqual(
+ recipes._op_properties_to_dict(op_args.properties.property),
+ {
+ u'a': u'Hello',
+ u'b': -12345L,
+ u'c': 12345L,
+ u'd': 3.14159,
+ u'e': True,
+ u'f': '\x60\x0d\xd0\x65',
+ u'g': {
+ u'foo': u'FOO!',
+ u'bar': {
+ u'baz': u'BAZ!',
+ },
+ },
+ u'h': [
+ u'foo',
+ u'bar',
+ u'baz',
+ ],
+ })
+
+
+if __name__ == '__main__':
+ result = unittest.main()
« recipes.py ('K') | « recipes.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698