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 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 Loading... | |
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' | |
46 | 50 |
M-A Ruel
2013/03/26 18:05:00
add another line.
Wez
2013/03/26 20:08:02
Done.
| |
47 class MockFile(object): | 51 class MockFile(object): |
48 def __init__(self, local_path, new_contents): | 52 def __init__(self, local_path, new_contents): |
49 self._local_path = local_path | 53 self._local_path = local_path |
50 self._new_contents = new_contents | 54 self._new_contents = new_contents |
51 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] | 55 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] |
52 | 56 |
53 def ChangedContents(self): | 57 def ChangedContents(self): |
54 return self._changed_contents | 58 return self._changed_contents |
55 | 59 |
56 def NewContents(self): | 60 def NewContents(self): |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 mock_output_api = MockOutputApi() | 243 mock_output_api = MockOutputApi() |
240 contents = ['#include <b.h>', | 244 contents = ['#include <b.h>', |
241 '#include <a.h>'] | 245 '#include <a.h>'] |
242 mock_file_cc = MockFile('something.cc', contents) | 246 mock_file_cc = MockFile('something.cc', contents) |
243 mock_file_h = MockFile('something.h', contents) | 247 mock_file_h = MockFile('something.h', contents) |
244 mock_file_other = MockFile('something.py', contents) | 248 mock_file_other = MockFile('something.py', contents) |
245 mock_input_api.files = [mock_file_cc, mock_file_h, mock_file_other] | 249 mock_input_api.files = [mock_file_cc, mock_file_h, mock_file_other] |
246 warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api) | 250 warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api) |
247 self.assertEqual(1, len(warnings)) | 251 self.assertEqual(1, len(warnings)) |
248 self.assertEqual(2, len(warnings[0].items)) | 252 self.assertEqual(2, len(warnings[0].items)) |
249 self.assertEqual('warning', warnings[0].type) | 253 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 | 254 |
263 def testUncheckableIncludes(self): | 255 def testUncheckableIncludes(self): |
264 mock_input_api = MockInputApi() | 256 mock_input_api = MockInputApi() |
265 contents = ['#include <windows.h>', | 257 contents = ['#include <windows.h>', |
266 '#include "b.h"' | 258 '#include "b.h"' |
267 '#include "a.h"'] | 259 '#include "a.h"'] |
268 mock_file = MockFile('', contents) | 260 mock_file = MockFile('', contents) |
269 warnings = PRESUBMIT._CheckIncludeOrderInFile( | 261 warnings = PRESUBMIT._CheckIncludeOrderInFile( |
270 mock_input_api, mock_file, range(1, len(contents) + 1)) | 262 mock_input_api, mock_file, range(1, len(contents) + 1)) |
271 self.assertEqual(0, len(warnings)) | 263 self.assertEqual(0, len(warnings)) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 | 363 |
372 def testValidOSMacroNames(self): | 364 def testValidOSMacroNames(self): |
373 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] | 365 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] |
374 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( | 366 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( |
375 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 367 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
376 self.assertEqual(0, len(errors)) | 368 self.assertEqual(0, len(errors)) |
377 | 369 |
378 | 370 |
379 if __name__ == '__main__': | 371 if __name__ == '__main__': |
380 unittest.main() | 372 unittest.main() |
OLD | NEW |