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

Side by Side Diff: PRESUBMIT_test.py

Issue 13093006: Update PRESUBMIT scripts to use PresubmitPromptOrNotify helper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « PRESUBMIT.py ('k') | ppapi/PRESUBMIT.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 os 6 import os
7 import re 7 import re
8 import unittest 8 import unittest
9 9
10 import PRESUBMIT 10 import PRESUBMIT
(...skipping 25 matching lines...) Expand all
36 class PresubmitPromptWarning(PresubmitResult): 36 class PresubmitPromptWarning(PresubmitResult):
37 def __init__(self, message, items, long_text=''): 37 def __init__(self, message, items, long_text=''):
38 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) 38 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
39 self.type = 'warning' 39 self.type = 'warning'
40 40
41 class PresubmitNotifyResult(PresubmitResult): 41 class PresubmitNotifyResult(PresubmitResult):
42 def __init__(self, message, items, long_text=''): 42 def __init__(self, message, items, long_text=''):
43 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) 43 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
44 self.type = 'notify' 44 self.type = 'notify'
45 45
46 class PresubmitPromptOrNotify(PresubmitResult):
47 def __init__(self, message, items, long_text=''):
48 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
49 self.type = 'promptOrNotify'
50
46 51
47 class MockFile(object): 52 class MockFile(object):
48 def __init__(self, local_path, new_contents): 53 def __init__(self, local_path, new_contents):
49 self._local_path = local_path 54 self._local_path = local_path
50 self._new_contents = new_contents 55 self._new_contents = new_contents
51 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] 56 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)]
52 57
53 def ChangedContents(self): 58 def ChangedContents(self):
54 return self._changed_contents 59 return self._changed_contents
55 60
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 mock_output_api = MockOutputApi() 244 mock_output_api = MockOutputApi()
240 contents = ['#include <b.h>', 245 contents = ['#include <b.h>',
241 '#include <a.h>'] 246 '#include <a.h>']
242 mock_file_cc = MockFile('something.cc', contents) 247 mock_file_cc = MockFile('something.cc', contents)
243 mock_file_h = MockFile('something.h', contents) 248 mock_file_h = MockFile('something.h', contents)
244 mock_file_other = MockFile('something.py', contents) 249 mock_file_other = MockFile('something.py', contents)
245 mock_input_api.files = [mock_file_cc, mock_file_h, mock_file_other] 250 mock_input_api.files = [mock_file_cc, mock_file_h, mock_file_other]
246 warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api) 251 warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api)
247 self.assertEqual(1, len(warnings)) 252 self.assertEqual(1, len(warnings))
248 self.assertEqual(2, len(warnings[0].items)) 253 self.assertEqual(2, len(warnings[0].items))
249 self.assertEqual('warning', warnings[0].type) 254 self.assertEqual('promptOrNotify', warnings[0].type)
250
251 def testOnlyNotifyOnCommit(self):
252 mock_input_api = MockInputApi()
253 mock_input_api.is_committing = True
254 mock_output_api = MockOutputApi()
255 contents = ['#include <b.h>',
256 '#include <a.h>']
257 mock_input_api.files = [MockFile('something.cc', contents)]
258 warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api)
259 self.assertEqual(1, len(warnings))
260 self.assertEqual(1, len(warnings[0].items))
261 self.assertEqual('notify', warnings[0].type)
262 255
263 def testUncheckableIncludes(self): 256 def testUncheckableIncludes(self):
264 mock_input_api = MockInputApi() 257 mock_input_api = MockInputApi()
265 contents = ['#include <windows.h>', 258 contents = ['#include <windows.h>',
266 '#include "b.h"' 259 '#include "b.h"'
267 '#include "a.h"'] 260 '#include "a.h"']
268 mock_file = MockFile('', contents) 261 mock_file = MockFile('', contents)
269 warnings = PRESUBMIT._CheckIncludeOrderInFile( 262 warnings = PRESUBMIT._CheckIncludeOrderInFile(
270 mock_input_api, mock_file, range(1, len(contents) + 1)) 263 mock_input_api, mock_file, range(1, len(contents) + 1))
271 self.assertEqual(0, len(warnings)) 264 self.assertEqual(0, len(warnings))
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 364
372 def testValidOSMacroNames(self): 365 def testValidOSMacroNames(self):
373 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] 366 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS]
374 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( 367 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
375 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 368 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
376 self.assertEqual(0, len(errors)) 369 self.assertEqual(0, len(errors))
377 370
378 371
379 if __name__ == '__main__': 372 if __name__ == '__main__':
380 unittest.main() 373 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | ppapi/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698