| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import client_api_generator | 7 import client_api_generator |
| 8 import shutil | 8 import shutil |
| 9 import sys | 9 import sys |
| 10 import tempfile | 10 import tempfile |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 'type': 'object', | 345 'type': 'object', |
| 346 'id': 'TestEventWithNoParamsParams', | 346 'id': 'TestEventWithNoParamsParams', |
| 347 'description': 'Parameters for the TestEventWithNoParams event.', | 347 'description': 'Parameters for the TestEventWithNoParams event.', |
| 348 'properties': [], | 348 'properties': [], |
| 349 } | 349 } |
| 350 ] | 350 ] |
| 351 client_api_generator.SynthesizeEventTypes(json_api) | 351 client_api_generator.SynthesizeEventTypes(json_api) |
| 352 types = json_api['domains'][0]['types'] | 352 types = json_api['domains'][0]['types'] |
| 353 self.assertListEqual(types, expected_types) | 353 self.assertListEqual(types, expected_types) |
| 354 | 354 |
| 355 def test_InitializeDomainDependencies(self): |
| 356 json_api = { |
| 357 'domains': [ |
| 358 { |
| 359 'domain': 'Domain1', |
| 360 'types': [ |
| 361 { |
| 362 'id': 'TestType', |
| 363 'type': 'object', |
| 364 'properties': [ |
| 365 {'name': 'p1', 'type': 'object', '$ref': 'Domain2.TestType'}, |
| 366 ], |
| 367 }, |
| 368 ], |
| 369 }, |
| 370 { |
| 371 'domain': 'Domain2', |
| 372 'dependencies': ['Domain3'], |
| 373 'types': [ |
| 374 { |
| 375 'id': 'TestType', |
| 376 'type': 'object', |
| 377 'properties': [ |
| 378 {'name': 'p1', 'type': 'object', '$ref': 'Domain1.TestType'}, |
| 379 ], |
| 380 }, |
| 381 ], |
| 382 }, |
| 383 { |
| 384 'domain': 'Domain3', |
| 385 }, |
| 386 { |
| 387 'domain': 'Domain4', |
| 388 'dependencies': ['Domain1'], |
| 389 }, |
| 390 ] |
| 391 } |
| 392 client_api_generator.InitializeDomainDependencies(json_api) |
| 393 |
| 394 dependencies = [ { |
| 395 'domain': domain['domain'], |
| 396 'dependencies': domain['dependencies'] |
| 397 } for domain in json_api['domains'] ] |
| 398 |
| 399 self.assertListEqual(dependencies, [ { |
| 400 "domain": "Domain1", |
| 401 "dependencies": ["Domain1", "Domain2", "Domain3"], |
| 402 }, { |
| 403 "domain": "Domain2", |
| 404 "dependencies": ["Domain1", "Domain2", "Domain3"], |
| 405 }, { |
| 406 "domain": "Domain3", |
| 407 "dependencies": ["Domain3"], |
| 408 }, { |
| 409 "domain": "Domain4", |
| 410 "dependencies": ["Domain1", "Domain2", "Domain3", "Domain4"], |
| 411 } |
| 412 ]) |
| 413 |
| 355 def test_PatchExperimentalDomains(self): | 414 def test_PatchExperimentalDomains(self): |
| 356 json_api = { | 415 json_api = { |
| 357 'domains': [ | 416 'domains': [ |
| 358 { | 417 { |
| 359 'domain': 'domain', | 418 'domain': 'domain', |
| 360 'experimental': True, | 419 'experimental': True, |
| 361 'commands': [ | 420 'commands': [ |
| 362 { | 421 { |
| 363 'name': 'FooCommand', | 422 'name': 'FooCommand', |
| 364 } | 423 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 ], | 507 ], |
| 449 }, | 508 }, |
| 450 ] | 509 ] |
| 451 }, | 510 }, |
| 452 ] | 511 ] |
| 453 } | 512 } |
| 454 try: | 513 try: |
| 455 dirname = tempfile.mkdtemp() | 514 dirname = tempfile.mkdtemp() |
| 456 jinja_env = client_api_generator.InitializeJinjaEnv(dirname) | 515 jinja_env = client_api_generator.InitializeJinjaEnv(dirname) |
| 457 client_api_generator.CreateTypeDefinitions(json_api) | 516 client_api_generator.CreateTypeDefinitions(json_api) |
| 458 client_api_generator.Generate(jinja_env, dirname, json_api, 'types', | 517 client_api_generator.Generate(jinja_env, dirname, json_api, |
| 459 ['cc']) | 518 'deprecated_types', ['h']) |
| 460 client_api_generator.Generate(jinja_env, dirname, json_api, 'types', | |
| 461 ['h']) | |
| 462 # This is just a smoke test; we don't actually verify the generated output | 519 # This is just a smoke test; we don't actually verify the generated output |
| 463 # here. | 520 # here. |
| 464 finally: | 521 finally: |
| 465 shutil.rmtree(dirname) | 522 shutil.rmtree(dirname) |
| 466 | 523 |
| 467 def test_GenerateDomains(self): | 524 def test_GenerateDomains(self): |
| 468 json_api = { | 525 json_api = { |
| 469 'domains': [ | 526 'domains': [ |
| 470 { | 527 { |
| 471 'domain': 'domain0', | 528 'domain': 'domain0', |
| (...skipping 11 matching lines...) Expand all Loading... |
| 483 'id': 'TestType', | 540 'id': 'TestType', |
| 484 'type': 'object', | 541 'type': 'object', |
| 485 }, | 542 }, |
| 486 ] | 543 ] |
| 487 }, | 544 }, |
| 488 ] | 545 ] |
| 489 } | 546 } |
| 490 try: | 547 try: |
| 491 dirname = tempfile.mkdtemp() | 548 dirname = tempfile.mkdtemp() |
| 492 jinja_env = client_api_generator.InitializeJinjaEnv(dirname) | 549 jinja_env = client_api_generator.InitializeJinjaEnv(dirname) |
| 493 client_api_generator.GenerateDomains(jinja_env, dirname, json_api, | 550 client_api_generator.GeneratePerDomain( |
| 494 'domain', ['cc', 'h']) | 551 jinja_env, dirname, json_api, |
| 552 'domain', ['cc', 'h'], lambda domain_name: domain_name) |
| 495 # This is just a smoke test; we don't actually verify the generated output | 553 # This is just a smoke test; we don't actually verify the generated output |
| 496 # here. | 554 # here. |
| 497 finally: | 555 finally: |
| 498 shutil.rmtree(dirname) | 556 shutil.rmtree(dirname) |
| 499 | 557 |
| 500 | 558 |
| 501 if __name__ == '__main__': | 559 if __name__ == '__main__': |
| 502 unittest.main(verbosity=2, exit=False, argv=sys.argv) | 560 unittest.main(verbosity=2, exit=False, argv=sys.argv) |
| OLD | NEW |