| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import StringIO | |
| 30 import logging | 29 import logging |
| 31 import os | 30 import os |
| 31 import StringIO |
| 32 | 32 |
| 33 from webkitpy.common.system.executive import ScriptError | 33 from webkitpy.common.system.executive import ScriptError |
| 34 | 34 |
| 35 _log = logging.getLogger(__name__) | 35 _log = logging.getLogger(__name__) |
| 36 | 36 |
| 37 | 37 |
| 38 class MockProcess(object): | 38 class MockProcess(object): |
| 39 | 39 |
| 40 def __init__(self, stdout='MOCK STDOUT\n', stderr=''): | 40 def __init__(self, stdout='MOCK STDOUT\n', stderr=''): |
| 41 self.pid = 42 | 41 self.pid = 42 |
| 42 self.stdout = StringIO.StringIO(stdout) | 42 self.stdout = StringIO.StringIO(stdout) |
| 43 self.stderr = StringIO.StringIO(stderr) | 43 self.stderr = StringIO.StringIO(stderr) |
| 44 self.stdin = StringIO.StringIO() | 44 self.stdin = StringIO.StringIO() |
| 45 self.returncode = 0 | 45 self.returncode = 0 |
| 46 | 46 |
| 47 def wait(self): | 47 def wait(self): |
| 48 return | 48 return |
| 49 | 49 |
| 50 def poll(self): | 50 def poll(self): |
| 51 # Consider the process completed when all the stdout and stderr has been
read. | 51 # Consider the process completed when all the stdout and stderr has been
read. |
| 52 if self.stdout.len != self.stdout.tell() or self.stderr.len != self.stde
rr.tell(): | 52 if self.stdout.len != self.stdout.tell() or self.stderr.len != self.stde
rr.tell(): |
| 53 return None | 53 return None |
| 54 return self.returncode | 54 return self.returncode |
| 55 | 55 |
| 56 def communicate(self, *_): | 56 def communicate(self, *_): |
| 57 return (self.stdout.getvalue(), self.stderr.getvalue()) | 57 return (self.stdout.getvalue(), self.stderr.getvalue()) |
| 58 | 58 |
| 59 | 59 |
| 60 # FIXME: This should be unified with MockExecutive2 (http://crbug.com/626115). | |
| 61 class MockExecutive(object): | 60 class MockExecutive(object): |
| 62 PIPE = "MOCK PIPE" | 61 PIPE = "MOCK PIPE" |
| 63 STDOUT = "MOCK STDOUT" | 62 STDOUT = "MOCK STDOUT" |
| 64 | 63 |
| 65 @staticmethod | 64 @staticmethod |
| 66 def ignore_error(error): | 65 def ignore_error(error): |
| 67 pass | 66 pass |
| 68 | 67 |
| 69 def __init__(self, should_log=False, should_throw=False, | 68 def __init__(self, should_log=False, should_throw=False, |
| 70 output="MOCK output of child process", stderr='', | 69 output="MOCK output of child process", stderr='', |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 new_calls = self.calls[num_previous_calls:] | 183 new_calls = self.calls[num_previous_calls:] |
| 185 self.calls = self.calls[:num_previous_calls] | 184 self.calls = self.calls[:num_previous_calls] |
| 186 self.calls.append(new_calls) | 185 self.calls.append(new_calls) |
| 187 return command_outputs | 186 return command_outputs |
| 188 | 187 |
| 189 def map(self, thunk, arglist, processes=None): | 188 def map(self, thunk, arglist, processes=None): |
| 190 return map(thunk, arglist) | 189 return map(thunk, arglist) |
| 191 | 190 |
| 192 def process_dump(self): | 191 def process_dump(self): |
| 193 return [] | 192 return [] |
| 194 | |
| 195 | |
| 196 class MockExecutive2(MockExecutive): | |
| 197 """MockExecutive2 is like MockExecutive except it doesn't log anything.""" | |
| 198 | |
| 199 def __init__(self, output='', exit_code=0, exception=None, run_command_fn=No
ne, stderr=''): | |
| 200 super(MockExecutive2, self).__init__() | |
| 201 self._output = output | |
| 202 self._stderr = stderr | |
| 203 self._exit_code = exit_code | |
| 204 self._exception = exception | |
| 205 self._run_command_fn = run_command_fn | |
| 206 | |
| 207 def run_command(self, | |
| 208 args, | |
| 209 cwd=None, | |
| 210 input=None, | |
| 211 error_handler=None, | |
| 212 return_exit_code=False, | |
| 213 return_stderr=True, | |
| 214 decode_output=False, | |
| 215 env=None, | |
| 216 debug_logging=False): | |
| 217 self.calls.append(args) | |
| 218 assert isinstance(args, list) or isinstance(args, tuple) | |
| 219 assert all(isinstance(arg, basestring) for arg in args) | |
| 220 if self._exception: | |
| 221 raise self._exception # pylint: disable=raising-bad-type | |
| 222 if self._run_command_fn: | |
| 223 return self._run_command_fn(args) | |
| 224 if return_exit_code: | |
| 225 return self._exit_code | |
| 226 if self._exit_code and error_handler: | |
| 227 script_error = ScriptError(script_args=args, exit_code=self._exit_co
de, output=self._output) | |
| 228 error_handler(script_error) | |
| 229 if return_stderr: | |
| 230 return self._output + self._stderr | |
| 231 return self._output | |
| OLD | NEW |