| 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 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 This class can be used to form the mock list of changed files in | 93 This class can be used to form the mock list of changed files in |
| 94 MockInputApi for presubmit unittests. | 94 MockInputApi for presubmit unittests. |
| 95 """ | 95 """ |
| 96 | 96 |
| 97 def __init__(self, local_path, new_contents, action='A'): | 97 def __init__(self, local_path, new_contents, action='A'): |
| 98 self._local_path = local_path | 98 self._local_path = local_path |
| 99 self._new_contents = new_contents | 99 self._new_contents = new_contents |
| 100 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] | 100 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] |
| 101 self._action = action | 101 self._action = action |
| 102 self._scm_diff = "--- /dev/null\n+++ %s\n@@ -0,0 +1,%d @@\n" % (local_path, |
| 103 len(new_contents)) |
| 104 for l in new_contents: |
| 105 self._scm_diff += "+%s\n" % l |
| 102 | 106 |
| 103 def Action(self): | 107 def Action(self): |
| 104 return self._action | 108 return self._action |
| 105 | 109 |
| 106 def ChangedContents(self): | 110 def ChangedContents(self): |
| 107 return self._changed_contents | 111 return self._changed_contents |
| 108 | 112 |
| 109 def NewContents(self): | 113 def NewContents(self): |
| 110 return self._new_contents | 114 return self._new_contents |
| 111 | 115 |
| 112 def LocalPath(self): | 116 def LocalPath(self): |
| 113 return self._local_path | 117 return self._local_path |
| 114 | 118 |
| 115 def AbsoluteLocalPath(self): | 119 def AbsoluteLocalPath(self): |
| 116 return self._local_path | 120 return self._local_path |
| 117 | 121 |
| 122 def GenerateScmDiff(self): |
| 123 return self._scm_diff; |
| 124 |
| 118 def rfind(self, p): | 125 def rfind(self, p): |
| 119 """os.path.basename is called on MockFile so we need an rfind method.""" | 126 """os.path.basename is called on MockFile so we need an rfind method.""" |
| 120 return self._local_path.rfind(p) | 127 return self._local_path.rfind(p) |
| 121 | 128 |
| 122 def __getitem__(self, i): | 129 def __getitem__(self, i): |
| 123 """os.path.basename is called on MockFile so we need a get method.""" | 130 """os.path.basename is called on MockFile so we need a get method.""" |
| 124 return self._local_path[i] | 131 return self._local_path[i] |
| 125 | 132 |
| 126 def __len__(self): | 133 def __len__(self): |
| 127 """os.path.basename is called on MockFile so we need a len method.""" | 134 """os.path.basename is called on MockFile so we need a len method.""" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 142 | 149 |
| 143 def __init__(self, changed_files): | 150 def __init__(self, changed_files): |
| 144 self._changed_files = changed_files | 151 self._changed_files = changed_files |
| 145 | 152 |
| 146 def LocalPaths(self): | 153 def LocalPaths(self): |
| 147 return self._changed_files | 154 return self._changed_files |
| 148 | 155 |
| 149 def AffectedFiles(self, include_dirs=False, include_deletes=True, | 156 def AffectedFiles(self, include_dirs=False, include_deletes=True, |
| 150 file_filter=None): | 157 file_filter=None): |
| 151 return self._changed_files | 158 return self._changed_files |
| OLD | NEW |