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

Side by Side Diff: PRESUBMIT_test.py

Issue 1067023003: Add shell::Tracer object and wire up to --trace-startup on Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 re 6 import re
7 import unittest 7 import unittest
8 8
9 import PRESUBMIT 9 import PRESUBMIT
10 from PRESUBMIT_test_mocks import MockChange, MockFile 10 from PRESUBMIT_test_mocks import MockChange, MockFile
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 'components/nacl/common/DEPS', 387 'components/nacl/common/DEPS',
388 'content/public/browser/render_process_host.h', 388 'content/public/browser/render_process_host.h',
389 'policy/DEPS', 389 'policy/DEPS',
390 'sandbox/DEPS', 390 'sandbox/DEPS',
391 'tools/memory_watcher/DEPS', 391 'tools/memory_watcher/DEPS',
392 'third_party/lss/linux_syscall_support.h', 392 'third_party/lss/linux_syscall_support.h',
393 ]) 393 ])
394 self.assertEqual(expected, files_to_check); 394 self.assertEqual(expected, files_to_check);
395 395
396 396
397 class JSONParsingTest(unittest.TestCase):
398 def testSuccess(self):
399 input_api = MockInputApi()
400 filename = 'valid_json.json'
401 contents = ['// This is a comment.',
402 '{',
403 ' "key1": ["value1", "value2"],',
404 ' "key2": 3 // This is an inline comment.',
405 '}'
406 ]
407 input_api.files = [MockFile(filename, contents)]
408 self.assertEqual(None,
409 PRESUBMIT._GetJSONParseError(input_api, filename))
410
411 def testFailure(self):
412 input_api = MockInputApi()
413 test_data = [
414 ('invalid_json_1.json',
415 ['{ x }'],
416 'Expecting property name:'),
417 ('invalid_json_2.json',
418 ['// Hello world!',
419 '{ "hello": "world }'],
420 'Unterminated string starting at:'),
421 ('invalid_json_3.json',
422 ['{ "a": "b", "c": "d", }'],
423 'Expecting property name:'),
424 ('invalid_json_4.json',
425 ['{ "a": "b" "c": "d" }'],
426 'Expecting , delimiter:'),
427 ]
428
429 input_api.files = [MockFile(filename, contents)
430 for (filename, contents, _) in test_data]
431
432 for (filename, _, expected_error) in test_data:
433 actual_error = PRESUBMIT._GetJSONParseError(input_api, filename)
434 self.assertTrue(expected_error in str(actual_error),
435 "'%s' not found in '%s'" % (expected_error, actual_error))
436
437 def testNoEatComments(self):
viettrungluu 2015/04/07 22:05:44 Maybe keep this test (and rename it)?
jamesr 2015/04/07 22:20:07 At this point it's just testing the JSON parser wh
438 input_api = MockInputApi()
439 file_with_comments = 'file_with_comments.json'
440 contents_with_comments = ['// This is a comment.',
441 '{',
442 ' "key1": ["value1", "value2"],',
443 ' "key2": 3 // This is an inline comment.',
444 '}'
445 ]
446 file_without_comments = 'file_without_comments.json'
447 contents_without_comments = ['{',
448 ' "key1": ["value1", "value2"],',
449 ' "key2": 3',
450 '}'
451 ]
452 input_api.files = [MockFile(file_with_comments, contents_with_comments),
453 MockFile(file_without_comments,
454 contents_without_comments)]
455
456 self.assertEqual('No JSON object could be decoded',
457 str(PRESUBMIT._GetJSONParseError(input_api,
458 file_with_comments,
459 eat_comments=False)))
460 self.assertEqual(None,
461 PRESUBMIT._GetJSONParseError(input_api,
462 file_without_comments,
463 eat_comments=False))
464
465 if __name__ == '__main__': 397 if __name__ == '__main__':
466 unittest.main() 398 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698