Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
| 6 import os | |
| 7 import re | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 | |
| 12 class MockInputApi(object): | |
|
brettw
2014/12/03 19:28:02
Can these classes have class-level comments explai
| |
| 13 def __init__(self): | |
| 14 self.json = json | |
| 15 self.re = re | |
| 16 self.os_path = os.path | |
| 17 self.python_executable = sys.executable | |
| 18 self.subprocess = subprocess | |
| 19 self.files = [] | |
| 20 self.is_committing = False | |
| 21 | |
| 22 def AffectedFiles(self, file_filter=None): | |
| 23 return self.files | |
| 24 | |
| 25 def PresubmitLocalPath(self): | |
| 26 return os.path.dirname(__file__) | |
| 27 | |
| 28 def ReadFile(self, filename, mode='rU'): | |
| 29 for file_ in self.files: | |
| 30 if file_.LocalPath() == filename: | |
| 31 return '\n'.join(file_.NewContents()) | |
| 32 # Otherwise, file is not in our mock API. | |
| 33 raise IOError, "No such file or directory: '%s'" % filename | |
| 34 | |
| 35 | |
| 36 class MockOutputApi(object): | |
| 37 class PresubmitResult(object): | |
| 38 def __init__(self, message, items=None, long_text=''): | |
| 39 self.message = message | |
| 40 self.items = items | |
| 41 self.long_text = long_text | |
| 42 | |
| 43 class PresubmitError(PresubmitResult): | |
| 44 def __init__(self, message, items, long_text=''): | |
| 45 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 46 self.type = 'error' | |
| 47 | |
| 48 class PresubmitPromptWarning(PresubmitResult): | |
| 49 def __init__(self, message, items, long_text=''): | |
| 50 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 51 self.type = 'warning' | |
| 52 | |
| 53 class PresubmitNotifyResult(PresubmitResult): | |
| 54 def __init__(self, message, items, long_text=''): | |
| 55 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 56 self.type = 'notify' | |
| 57 | |
| 58 class PresubmitPromptOrNotify(PresubmitResult): | |
| 59 def __init__(self, message, items, long_text=''): | |
| 60 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) | |
| 61 self.type = 'promptOrNotify' | |
| 62 | |
| 63 | |
| 64 class MockFile(object): | |
| 65 def __init__(self, local_path, new_contents): | |
| 66 self._local_path = local_path | |
| 67 self._new_contents = new_contents | |
| 68 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] | |
| 69 | |
| 70 def ChangedContents(self): | |
| 71 return self._changed_contents | |
| 72 | |
| 73 def NewContents(self): | |
| 74 return self._new_contents | |
| 75 | |
| 76 def LocalPath(self): | |
| 77 return self._local_path | |
| 78 | |
| 79 | |
| 80 class MockChange(object): | |
| 81 def __init__(self, changed_files): | |
| 82 self._changed_files = changed_files | |
| 83 | |
| 84 def LocalPaths(self): | |
| 85 return self._changed_files | |
| OLD | NEW |