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.platform = sys.platform |
26 self.subprocess = subprocess | 26 self.subprocess = subprocess |
27 self.files = [] | 27 self.files = [] |
28 self.is_committing = False | 28 self.is_committing = False |
29 self.change = MockChange([]) | 29 self.change = MockChange([]) |
30 self.presubmitLocalPath = os.path.dirname(__file__) | |
Dan Beam
2017/05/31 01:40:31
presubmit_local_path
| |
30 | 31 |
31 def AffectedFiles(self, file_filter=None, include_deletes=False): | 32 def AffectedFiles(self, file_filter=None, include_deletes=False): |
32 return self.files | 33 return self.files |
33 | 34 |
34 def AffectedSourceFiles(self, file_filter=None): | 35 def AffectedSourceFiles(self, file_filter=None): |
35 return self.files | 36 return self.files |
36 | 37 |
37 def LocalPaths(self): | 38 def LocalPaths(self): |
38 return self.files | 39 return self.files |
39 | 40 |
40 def PresubmitLocalPath(self): | 41 def PresubmitLocalPath(self): |
41 return os.path.dirname(__file__) | 42 return self.presubmitLocalPath |
42 | 43 |
43 def ReadFile(self, filename, mode='rU'): | 44 def ReadFile(self, filename, mode='rU'): |
44 if hasattr(filename, 'AbsoluteLocalPath'): | 45 if hasattr(filename, 'AbsoluteLocalPath'): |
45 filename = filename.AbsoluteLocalPath() | 46 filename = filename.AbsoluteLocalPath() |
46 for file_ in self.files: | 47 for file_ in self.files: |
47 if file_.LocalPath() == filename: | 48 if file_.LocalPath() == filename: |
48 return '\n'.join(file_.NewContents()) | 49 return '\n'.join(file_.NewContents()) |
49 # Otherwise, file is not in our mock API. | 50 # Otherwise, file is not in our mock API. |
50 raise IOError, "No such file or directory: '%s'" % filename | 51 raise IOError, "No such file or directory: '%s'" % filename |
51 | 52 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 | 150 |
150 def __init__(self, changed_files): | 151 def __init__(self, changed_files): |
151 self._changed_files = changed_files | 152 self._changed_files = changed_files |
152 | 153 |
153 def LocalPaths(self): | 154 def LocalPaths(self): |
154 return self._changed_files | 155 return self._changed_files |
155 | 156 |
156 def AffectedFiles(self, include_dirs=False, include_deletes=True, | 157 def AffectedFiles(self, include_dirs=False, include_deletes=True, |
157 file_filter=None): | 158 file_filter=None): |
158 return self._changed_files | 159 return self._changed_files |
OLD | NEW |