OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 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 json | 6 import json |
7 import os | 7 import os |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import unittest | 10 import unittest |
11 import tempfile | 11 import tempfile |
12 import time | 12 import time |
13 | 13 |
14 import test_env | 14 import test_env |
15 from test_env import BASE_DIR | 15 from test_env import BASE_DIR |
16 | 16 |
17 import recipe_engine.run | 17 import recipe_engine.run |
18 import recipe_engine.step_runner | 18 import recipe_engine.step_runner |
| 19 from recipe_engine import arguments_pb2 |
| 20 from google.protobuf import json_format as jsonpb |
19 from recipe_engine import requests_ssl | 21 from recipe_engine import requests_ssl |
20 | 22 |
21 class RunTest(unittest.TestCase): | 23 class RunTest(unittest.TestCase): |
22 def _run_cmd(self, recipe, properties=None, engine_args=None): | 24 def _run_cmd(self, recipe, properties=None, engine_args=None): |
23 script_path = os.path.join(BASE_DIR, 'recipes.py') | 25 script_path = os.path.join(BASE_DIR, 'recipes.py') |
24 | 26 |
25 if properties: | 27 if properties: |
26 proplist = [ '%s=%s' % (k, json.dumps(v)) | 28 proplist = [ '%s=%s' % (k, json.dumps(v)) |
27 for k,v in properties.iteritems() ] | 29 for k,v in properties.iteritems() ] |
28 else: | 30 else: |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 stderr=subprocess.PIPE) | 195 stderr=subprocess.PIPE) |
194 stdout, _ = proc.communicate() | 196 stdout, _ = proc.communicate() |
195 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') | 197 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') |
196 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') | 198 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') |
197 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the | 199 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the |
198 # state. | 200 # state. |
199 self.assertRegexpMatches(stdout, | 201 self.assertRegexpMatches(stdout, |
200 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') | 202 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') |
201 | 203 |
202 | 204 |
| 205 class TestOperationalArgs(unittest.TestCase): |
| 206 def test_operational_arg_parsing(self): |
| 207 # For convenience, we'll define the JSONPB data as a Python dict that we |
| 208 # will then dump into JSON. |
| 209 op_args = jsonpb.Parse(json.dumps({ |
| 210 'properties': {'property': { |
| 211 'a': {'s': 'Hello'}, |
| 212 'b': {'int': -12345}, |
| 213 'c': {'uint': 12345}, |
| 214 'd': {'d': 3.14159}, |
| 215 'e': {'b': True}, |
| 216 'f': {'data': '\x60\x0d\xd0\x65'.encode('base64')}, |
| 217 'g': {'map': { |
| 218 'property': { |
| 219 'foo': {'s': 'FOO!'}, |
| 220 'bar': {'map': { |
| 221 'property': { |
| 222 'baz': {'s': 'BAZ!'}, |
| 223 }, |
| 224 }}, |
| 225 }}, |
| 226 }, |
| 227 'h': {'list': { |
| 228 'property': [ |
| 229 {'s': 'foo'}, |
| 230 {'s': 'bar'}, |
| 231 {'s': 'baz'}, |
| 232 ], |
| 233 }}, |
| 234 }}, |
| 235 'annotationFlags': { |
| 236 'emitTimestamp': True, |
| 237 }, |
| 238 }), arguments_pb2.Arguments()) |
| 239 |
| 240 self.assertEqual( |
| 241 recipe_engine.run._op_properties_to_dict(op_args.properties.property), |
| 242 { |
| 243 u'a': u'Hello', |
| 244 u'b': -12345L, |
| 245 u'c': 12345L, |
| 246 u'd': 3.14159, |
| 247 u'e': True, |
| 248 u'f': '\x60\x0d\xd0\x65', |
| 249 u'g': { |
| 250 u'foo': u'FOO!', |
| 251 u'bar': { |
| 252 u'baz': u'BAZ!', |
| 253 }, |
| 254 }, |
| 255 u'h': [ |
| 256 u'foo', |
| 257 u'bar', |
| 258 u'baz', |
| 259 ], |
| 260 }) |
| 261 |
| 262 |
203 if __name__ == '__main__': | 263 if __name__ == '__main__': |
204 unittest.TestCase.maxDiff = None | 264 unittest.TestCase.maxDiff = None |
205 unittest.main() | 265 unittest.main() |
OLD | NEW |