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.python_executable = sys.executable | 23 self.python_executable = sys.executable |
24 self.subprocess = subprocess | 24 self.subprocess = subprocess |
25 self.files = [] | 25 self.files = [] |
26 self.is_committing = False | 26 self.is_committing = False |
| 27 self.change = MockChange([]) |
27 | 28 |
28 def AffectedFiles(self, file_filter=None): | 29 def AffectedFiles(self, file_filter=None): |
29 return self.files | 30 return self.files |
30 | 31 |
31 def PresubmitLocalPath(self): | 32 def PresubmitLocalPath(self): |
32 return os.path.dirname(__file__) | 33 return os.path.dirname(__file__) |
33 | 34 |
34 def ReadFile(self, filename, mode='rU'): | 35 def ReadFile(self, filename, mode='rU'): |
35 for file_ in self.files: | 36 for file_ in self.files: |
36 if file_.LocalPath() == filename: | 37 if file_.LocalPath() == filename: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 101 |
101 This class can be used in presubmit unittests to mock the query of the | 102 This class can be used in presubmit unittests to mock the query of the |
102 current change. | 103 current change. |
103 """ | 104 """ |
104 | 105 |
105 def __init__(self, changed_files): | 106 def __init__(self, changed_files): |
106 self._changed_files = changed_files | 107 self._changed_files = changed_files |
107 | 108 |
108 def LocalPaths(self): | 109 def LocalPaths(self): |
109 return self._changed_files | 110 return self._changed_files |
OLD | NEW |