OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import os | 6 import os |
7 import re | 7 import re |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 | 10 |
11 | 11 |
12 class MockInputApi(object): | 12 class MockInputApi(object): |
13 """Mock class for the InputApi class. | 13 """Mock class for the InputApi class. |
14 | 14 |
15 This class can be used for unittests for presubmit by initializing the files | 15 This class can be used for unittests for presubmit by initializing the files |
16 attribute as the list of changed files. | 16 attribute as the list of changed files. |
17 """ | 17 """ |
18 | 18 |
19 def __init__(self): | 19 def __init__(self): |
20 self.json = json | 20 self.json = json |
21 self.re = re | 21 self.re = re |
22 self.os_path = os.path | 22 self.os_path = os.path |
23 self.platform = sys.platform | 23 self.platform = sys.platform |
24 self.python_executable = sys.executable | 24 self.python_executable = sys.executable |
| 25 self.platform = sys.platform |
25 self.subprocess = subprocess | 26 self.subprocess = subprocess |
26 self.files = [] | 27 self.files = [] |
27 self.is_committing = False | 28 self.is_committing = False |
28 self.change = MockChange([]) | 29 self.change = MockChange([]) |
29 | 30 |
30 def AffectedFiles(self, file_filter=None, include_deletes=False): | 31 def AffectedFiles(self, file_filter=None, include_deletes=False): |
31 return self.files | 32 return self.files |
32 | 33 |
33 def AffectedSourceFiles(self, file_filter=None): | 34 def AffectedSourceFiles(self, file_filter=None): |
34 return self.files | 35 return self.files |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return self._local_path | 116 return self._local_path |
116 | 117 |
117 def rfind(self, p): | 118 def rfind(self, p): |
118 """os.path.basename is called on MockFile so we need an rfind method.""" | 119 """os.path.basename is called on MockFile so we need an rfind method.""" |
119 return self._local_path.rfind(p) | 120 return self._local_path.rfind(p) |
120 | 121 |
121 def __getitem__(self, i): | 122 def __getitem__(self, i): |
122 """os.path.basename is called on MockFile so we need a get method.""" | 123 """os.path.basename is called on MockFile so we need a get method.""" |
123 return self._local_path[i] | 124 return self._local_path[i] |
124 | 125 |
| 126 def __len__(self): |
| 127 """os.path.basename is called on MockFile so we need a len method.""" |
| 128 return len(self._local_path) |
| 129 |
125 | 130 |
126 class MockAffectedFile(MockFile): | 131 class MockAffectedFile(MockFile): |
127 def AbsoluteLocalPath(self): | 132 def AbsoluteLocalPath(self): |
128 return self._local_path | 133 return self._local_path |
129 | 134 |
130 | 135 |
131 class MockChange(object): | 136 class MockChange(object): |
132 """Mock class for Change class. | 137 """Mock class for Change class. |
133 | 138 |
134 This class can be used in presubmit unittests to mock the query of the | 139 This class can be used in presubmit unittests to mock the query of the |
135 current change. | 140 current change. |
136 """ | 141 """ |
137 | 142 |
138 def __init__(self, changed_files): | 143 def __init__(self, changed_files): |
139 self._changed_files = changed_files | 144 self._changed_files = changed_files |
140 | 145 |
141 def LocalPaths(self): | 146 def LocalPaths(self): |
142 return self._changed_files | 147 return self._changed_files |
143 | 148 |
144 def AffectedFiles(self, include_dirs=False, include_deletes=True, | 149 def AffectedFiles(self, include_dirs=False, include_deletes=True, |
145 file_filter=None): | 150 file_filter=None): |
146 return self._changed_files | 151 return self._changed_files |
OLD | NEW |