Chromium Code Reviews| 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 |
| 11 import sys | 11 import sys |
| 12 import unittest | 12 import unittest |
| 13 | 13 |
| 14 import PRESUBMIT | 14 import PRESUBMIT |
| 15 | 15 from PRESUBMIT_test_mocks import MockFile, MockInputApi, MockOutputApi,\ |
|
M-A Ruel
2014/11/26 18:15:48
use multiple from statements;
from PRESUBMIT_test_
gayane -on leave until 09-2017
2014/11/26 20:28:46
Done.
| |
| 16 MockChange | |
| 16 | 17 |
| 17 _TEST_DATA_DIR = 'base/test/data/presubmit' | 18 _TEST_DATA_DIR = 'base/test/data/presubmit' |
| 18 | 19 |
| 19 | |
| 20 class MockInputApi(object): | |
| 21 def __init__(self): | |
| 22 self.json = json | |
| 23 self.re = re | |
| 24 self.os_path = os.path | |
| 25 self.python_executable = sys.executable | |
| 26 self.subprocess = subprocess | |
| 27 self.files = [] | |
| 28 self.is_committing = False | |
| 29 | |
| 30 def AffectedFiles(self, file_filter=None): | |
| 31 return self.files | |
| 32 | |
| 33 def PresubmitLocalPath(self): | |
| 34 return os.path.dirname(__file__) | |
| 35 | |
| 36 def ReadFile(self, filename, mode='rU'): | |
| 37 for file_ in self.files: | |
| 38 if file_.LocalPath() == filename: | |
| 39 return '\n'.join(file_.NewContents()) | |
| 40 # Otherwise, file is not in our mock API. | |
| 41 raise IOError, "No such file or directory: '%s'" % filename | |
| 42 | |
| 43 | |
| 44 class MockOutputApi(object): | |
| 45 class PresubmitResult(object): | |
| 46 def __init__(self, message, items=None, long_text=''): | |
| 47 self.message = message | |
| 48 self.items = items | |
| 49 self.long_text = long_text | |
| 50 | |
| 51 class PresubmitError(PresubmitResult): | |
| 52 def __init__(self, message, items, long_text=''): | |
| 53 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 54 self.type = 'error' | |
| 55 | |
| 56 class PresubmitPromptWarning(PresubmitResult): | |
| 57 def __init__(self, message, items, long_text=''): | |
| 58 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 59 self.type = 'warning' | |
| 60 | |
| 61 class PresubmitNotifyResult(PresubmitResult): | |
| 62 def __init__(self, message, items, long_text=''): | |
| 63 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 64 self.type = 'notify' | |
| 65 | |
| 66 class PresubmitPromptOrNotify(PresubmitResult): | |
| 67 def __init__(self, message, items, long_text=''): | |
| 68 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 69 self.type = 'promptOrNotify' | |
| 70 | |
| 71 | |
| 72 class MockFile(object): | |
| 73 def __init__(self, local_path, new_contents): | |
| 74 self._local_path = local_path | |
| 75 self._new_contents = new_contents | |
| 76 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] | |
| 77 | |
| 78 def ChangedContents(self): | |
| 79 return self._changed_contents | |
| 80 | |
| 81 def NewContents(self): | |
| 82 return self._new_contents | |
| 83 | |
| 84 def LocalPath(self): | |
| 85 return self._local_path | |
| 86 | |
| 87 | |
| 88 class MockChange(object): | |
| 89 def __init__(self, changed_files): | |
| 90 self._changed_files = changed_files | |
| 91 | |
| 92 def LocalPaths(self): | |
| 93 return self._changed_files | |
| 94 | |
| 95 | |
| 96 class IncludeOrderTest(unittest.TestCase): | 20 class IncludeOrderTest(unittest.TestCase): |
| 97 def testSystemHeaderOrder(self): | 21 def testSystemHeaderOrder(self): |
| 98 scope = [(1, '#include <csystem.h>'), | 22 scope = [(1, '#include <csystem.h>'), |
| 99 (2, '#include <cppsystem>'), | 23 (2, '#include <cppsystem>'), |
| 100 (3, '#include "acustom.h"')] | 24 (3, '#include "acustom.h"')] |
| 101 all_linenums = [linenum for (linenum, _) in scope] | 25 all_linenums = [linenum for (linenum, _) in scope] |
| 102 mock_input_api = MockInputApi() | 26 mock_input_api = MockInputApi() |
| 103 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, | 27 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, |
| 104 '', all_linenums) | 28 '', all_linenums) |
| 105 self.assertEqual(0, len(warnings)) | 29 self.assertEqual(0, len(warnings)) |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 768 } | 692 } |
| 769 for master, bots in bots.iteritems(): | 693 for master, bots in bots.iteritems(): |
| 770 for bot in bots: | 694 for bot in bots: |
| 771 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), | 695 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), |
| 772 'bot=%s: expected %s, computed %s' % ( | 696 'bot=%s: expected %s, computed %s' % ( |
| 773 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) | 697 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) |
| 774 | 698 |
| 775 | 699 |
| 776 if __name__ == '__main__': | 700 if __name__ == '__main__': |
| 777 unittest.main() | 701 unittest.main() |
| OLD | NEW |