OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import glob | 6 import glob |
7 import json | 7 import json |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 ] | 463 ] |
464 input_api.files = [MockFile(filename, contents)] | 464 input_api.files = [MockFile(filename, contents)] |
465 self.assertEqual(None, | 465 self.assertEqual(None, |
466 PRESUBMIT._GetJSONParseError(input_api, filename)) | 466 PRESUBMIT._GetJSONParseError(input_api, filename)) |
467 | 467 |
468 def testFailure(self): | 468 def testFailure(self): |
469 input_api = MockInputApi() | 469 input_api = MockInputApi() |
470 test_data = [ | 470 test_data = [ |
471 ('invalid_json_1.json', | 471 ('invalid_json_1.json', |
472 ['{ x }'], | 472 ['{ x }'], |
473 'Expecting property name: line 1 column 2 (char 2)'), | 473 'Expecting property name:'), |
474 ('invalid_json_2.json', | 474 ('invalid_json_2.json', |
475 ['// Hello world!', | 475 ['// Hello world!', |
476 '{ "hello": "world }'], | 476 '{ "hello": "world }'], |
477 'Unterminated string starting at: line 2 column 12 (char 12)'), | 477 'Unterminated string starting at:'), |
478 ('invalid_json_3.json', | 478 ('invalid_json_3.json', |
479 ['{ "a": "b", "c": "d", }'], | 479 ['{ "a": "b", "c": "d", }'], |
480 'Expecting property name: line 1 column 22 (char 22)'), | 480 'Expecting property name:'), |
481 ('invalid_json_4.json', | 481 ('invalid_json_4.json', |
482 ['{ "a": "b" "c": "d" }'], | 482 ['{ "a": "b" "c": "d" }'], |
483 'Expecting , delimiter: line 1 column 11 (char 11)'), | 483 'Expecting , delimiter:'), |
484 ] | 484 ] |
485 | 485 |
486 input_api.files = [MockFile(filename, contents) | 486 input_api.files = [MockFile(filename, contents) |
487 for (filename, contents, _) in test_data] | 487 for (filename, contents, _) in test_data] |
488 | 488 |
489 for (filename, _, expected_error) in test_data: | 489 for (filename, _, expected_error) in test_data: |
490 actual_error = PRESUBMIT._GetJSONParseError(input_api, filename) | 490 actual_error = PRESUBMIT._GetJSONParseError(input_api, filename) |
491 self.assertEqual(expected_error, str(actual_error)) | 491 self.assertTrue(expected_error in str(actual_error), |
| 492 "'%s' not found in '%s'" % (expected_error, actual_error)) |
492 | 493 |
493 def testNoEatComments(self): | 494 def testNoEatComments(self): |
494 input_api = MockInputApi() | 495 input_api = MockInputApi() |
495 file_with_comments = 'file_with_comments.json' | 496 file_with_comments = 'file_with_comments.json' |
496 contents_with_comments = ['// This is a comment.', | 497 contents_with_comments = ['// This is a comment.', |
497 '{', | 498 '{', |
498 ' "key1": ["value1", "value2"],', | 499 ' "key1": ["value1", "value2"],', |
499 ' "key2": 3 // This is an inline comment.', | 500 ' "key2": 3 // This is an inline comment.', |
500 '}' | 501 '}' |
501 ] | 502 ] |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 for (filename, contents, _) in test_data] | 643 for (filename, contents, _) in test_data] |
643 | 644 |
644 for (filename, _, expected_error) in test_data: | 645 for (filename, _, expected_error) in test_data: |
645 actual_error = PRESUBMIT._GetIDLParseError(input_api, filename) | 646 actual_error = PRESUBMIT._GetIDLParseError(input_api, filename) |
646 self.assertTrue(expected_error in str(actual_error), | 647 self.assertTrue(expected_error in str(actual_error), |
647 "'%s' not found in '%s'" % (expected_error, actual_error)) | 648 "'%s' not found in '%s'" % (expected_error, actual_error)) |
648 | 649 |
649 | 650 |
650 if __name__ == '__main__': | 651 if __name__ == '__main__': |
651 unittest.main() | 652 unittest.main() |
OLD | NEW |