OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import client_api_generator | 6 import client_api_generator |
7 import shutil | 7 import shutil |
8 import sys | 8 import sys |
9 import tempfile | 9 import tempfile |
10 import unittest | 10 import unittest |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 {'type': 'string', 'name': 'r4'}, | 293 {'type': 'string', 'name': 'r4'}, |
294 {'type': 'any', 'name': 'r5'}, | 294 {'type': 'any', 'name': 'r5'}, |
295 {'type': 'object', 'name': 'r6', '$ref': 'TestType'} | 295 {'type': 'object', 'name': 'r6', '$ref': 'TestType'} |
296 ], | 296 ], |
297 } | 297 } |
298 ] | 298 ] |
299 client_api_generator.SynthesizeCommandTypes(json_api) | 299 client_api_generator.SynthesizeCommandTypes(json_api) |
300 types = json_api['domains'][0]['types'] | 300 types = json_api['domains'][0]['types'] |
301 self.assertListEqual(types, expected_types) | 301 self.assertListEqual(types, expected_types) |
302 | 302 |
| 303 def test_SynthesizeEventTypes(self): |
| 304 json_api = { |
| 305 'domains': [ |
| 306 { |
| 307 'domain': 'domain', |
| 308 'events': [ |
| 309 { |
| 310 'name': 'TestEvent', |
| 311 'parameters': [ |
| 312 {'name': 'p1', 'type': 'number'}, |
| 313 {'name': 'p2', 'type': 'integer'}, |
| 314 {'name': 'p3', 'type': 'boolean'}, |
| 315 {'name': 'p4', 'type': 'string'}, |
| 316 {'name': 'p5', 'type': 'any'}, |
| 317 {'name': 'p6', 'type': 'object', '$ref': 'TestType'}, |
| 318 ] |
| 319 }, |
| 320 { |
| 321 'name': 'TestEventWithNoParams', |
| 322 } |
| 323 ] |
| 324 } |
| 325 ] |
| 326 } |
| 327 expected_types = [ |
| 328 { |
| 329 'type': 'object', |
| 330 'id': 'TestEventParams', |
| 331 'description': 'Parameters for the TestEvent event.', |
| 332 'properties': [ |
| 333 {'type': 'number', 'name': 'p1'}, |
| 334 {'type': 'integer', 'name': 'p2'}, |
| 335 {'type': 'boolean', 'name': 'p3'}, |
| 336 {'type': 'string', 'name': 'p4'}, |
| 337 {'type': 'any', 'name': 'p5'}, |
| 338 {'type': 'object', 'name': 'p6', '$ref': 'TestType'} |
| 339 ] |
| 340 } |
| 341 ] |
| 342 client_api_generator.SynthesizeEventTypes(json_api) |
| 343 types = json_api['domains'][0]['types'] |
| 344 self.assertListEqual(types, expected_types) |
| 345 |
303 def test_Generate(self): | 346 def test_Generate(self): |
304 json_api = { | 347 json_api = { |
305 'domains': [ | 348 'domains': [ |
306 { | 349 { |
307 'domain': 'domain', | 350 'domain': 'domain', |
308 'types': [ | 351 'types': [ |
309 { | 352 { |
310 'id': 'TestType', | 353 'id': 'TestType', |
311 'type': 'object', | 354 'type': 'object', |
312 'properties': [ | 355 'properties': [ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 420 |
378 | 421 |
379 if __name__ == '__main__': | 422 if __name__ == '__main__': |
380 cmdline_parser = argparse.ArgumentParser() | 423 cmdline_parser = argparse.ArgumentParser() |
381 cmdline_parser.add_argument('--stamp') | 424 cmdline_parser.add_argument('--stamp') |
382 args = cmdline_parser.parse_args() | 425 args = cmdline_parser.parse_args() |
383 unittest.main(verbosity=2, exit=False, argv=sys.argv[:1]) | 426 unittest.main(verbosity=2, exit=False, argv=sys.argv[:1]) |
384 if args.stamp: | 427 if args.stamp: |
385 with open(args.stamp, 'a') as f: | 428 with open(args.stamp, 'a') as f: |
386 pass | 429 pass |
OLD | NEW |