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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 import StringIO | 29 import StringIO |
30 import logging | 30 import logging |
31 import os | 31 import os |
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 def __init__(self, stdout='MOCK STDOUT\n', stderr=''): | 40 def __init__(self, stdout='MOCK STDOUT\n', stderr=''): |
40 self.pid = 42 | 41 self.pid = 42 |
41 self.stdout = StringIO.StringIO(stdout) | 42 self.stdout = StringIO.StringIO(stdout) |
42 self.stderr = StringIO.StringIO(stderr) | 43 self.stderr = StringIO.StringIO(stderr) |
43 self.stdin = StringIO.StringIO() | 44 self.stdin = StringIO.StringIO() |
44 self.returncode = 0 | 45 self.returncode = 0 |
45 | 46 |
46 def wait(self): | 47 def wait(self): |
47 return | 48 return |
48 | 49 |
49 def poll(self): | 50 def poll(self): |
50 # 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. |
51 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(): |
52 return None | 53 return None |
53 return self.returncode | 54 return self.returncode |
54 | 55 |
55 # FIXME: This should be unified with MockExecutive2 | 56 # FIXME: This should be unified with MockExecutive2 |
| 57 |
| 58 |
56 class MockExecutive(object): | 59 class MockExecutive(object): |
57 PIPE = "MOCK PIPE" | 60 PIPE = "MOCK PIPE" |
58 STDOUT = "MOCK STDOUT" | 61 STDOUT = "MOCK STDOUT" |
59 | 62 |
60 @staticmethod | 63 @staticmethod |
61 def ignore_error(error): | 64 def ignore_error(error): |
62 pass | 65 pass |
63 | 66 |
64 def __init__(self, should_log=False, should_throw=False, | 67 def __init__(self, should_log=False, should_throw=False, |
65 should_throw_when_run=None, should_return_zero_when_run=None): | 68 should_throw_when_run=None, should_return_zero_when_run=None): |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 self.calls = self.calls[:num_previous_calls] | 165 self.calls = self.calls[:num_previous_calls] |
163 self.calls.append(new_calls) | 166 self.calls.append(new_calls) |
164 return command_outputs | 167 return command_outputs |
165 | 168 |
166 def map(self, thunk, arglist, processes=None): | 169 def map(self, thunk, arglist, processes=None): |
167 return map(thunk, arglist) | 170 return map(thunk, arglist) |
168 | 171 |
169 def process_dump(self): | 172 def process_dump(self): |
170 return [] | 173 return [] |
171 | 174 |
| 175 |
172 class MockExecutive2(MockExecutive): | 176 class MockExecutive2(MockExecutive): |
173 """MockExecutive2 is like MockExecutive except it doesn't log anything.""" | 177 """MockExecutive2 is like MockExecutive except it doesn't log anything.""" |
174 | 178 |
175 def __init__(self, output='', exit_code=0, exception=None, run_command_fn=No
ne, stderr=''): | 179 def __init__(self, output='', exit_code=0, exception=None, run_command_fn=No
ne, stderr=''): |
176 self._output = output | 180 self._output = output |
177 self._stderr = stderr | 181 self._stderr = stderr |
178 self._exit_code = exit_code | 182 self._exit_code = exit_code |
179 self._exception = exception | 183 self._exception = exception |
180 self._run_command_fn = run_command_fn | 184 self._run_command_fn = run_command_fn |
181 self.calls = [] | 185 self.calls = [] |
(...skipping 15 matching lines...) Expand all Loading... |
197 if self._run_command_fn: | 201 if self._run_command_fn: |
198 return self._run_command_fn(args) | 202 return self._run_command_fn(args) |
199 if return_exit_code: | 203 if return_exit_code: |
200 return self._exit_code | 204 return self._exit_code |
201 if self._exit_code and error_handler: | 205 if self._exit_code and error_handler: |
202 script_error = ScriptError(script_args=args, exit_code=self._exit_co
de, output=self._output) | 206 script_error = ScriptError(script_args=args, exit_code=self._exit_co
de, output=self._output) |
203 error_handler(script_error) | 207 error_handler(script_error) |
204 if return_stderr: | 208 if return_stderr: |
205 return self._output + self._stderr | 209 return self._output + self._stderr |
206 return self._output | 210 return self._output |
OLD | NEW |