Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1140)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/executive_mock.py

Issue 2496633002: W3C auto importer: Add a buildbot job link to CL description. (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/deps_updater.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 # FIXME: This should be unified with MockExecutive2 56 def communicate(self, *_):
57 return (self.stdout.getvalue(), self.stderr.getvalue())
57 58
58 59
60 # FIXME: This should be unified with MockExecutive2 (http://crbug.com/626115).
59 class MockExecutive(object): 61 class MockExecutive(object):
60 PIPE = "MOCK PIPE" 62 PIPE = "MOCK PIPE"
61 STDOUT = "MOCK STDOUT" 63 STDOUT = "MOCK STDOUT"
62 64
63 @staticmethod 65 @staticmethod
64 def ignore_error(error): 66 def ignore_error(error):
65 pass 67 pass
66 68
67 def __init__(self, should_log=False, should_throw=False, 69 def __init__(self, should_log=False, should_throw=False,
68 should_throw_when_run=None, should_return_zero_when_run=None): 70 should_throw_when_run=None, should_return_zero_when_run=None):
69 self._should_log = should_log 71 self._should_log = should_log
70 self._should_throw = should_throw 72 self._should_throw = should_throw
71 self._should_throw_when_run = should_throw_when_run or set() 73 self._should_throw_when_run = should_throw_when_run or set()
72 self._should_return_zero_when_run = should_return_zero_when_run or set() 74 self._should_return_zero_when_run = should_return_zero_when_run or set()
73 # FIXME: Once executive wraps os.getpid() we can just use a static pid f or "this" process. 75 # FIXME: Once executive wraps os.getpid() we can just use a static pid f or "this" process.
74 self._running_pids = {'test-webkitpy': os.getpid()} 76 self._running_pids = {'test-webkitpy': os.getpid()}
77 self.calls = []
78 self._output = "MOCK output of child process"
75 self._proc = None 79 self._proc = None
76 self.calls = []
77 80
78 def check_running_pid(self, pid): 81 def check_running_pid(self, pid):
79 return pid in self._running_pids.values() 82 return pid in self._running_pids.values()
80 83
81 def running_pids(self, process_name_filter): 84 def running_pids(self, process_name_filter):
82 running_pids = [] 85 running_pids = []
83 for process_name, process_pid in self._running_pids.iteritems(): 86 for process_name, process_pid in self._running_pids.iteritems():
84 if process_name_filter(process_name): 87 if process_name_filter(process_name):
85 running_pids.append(process_pid) 88 running_pids.append(process_pid)
86 89
(...skipping 22 matching lines...) Expand all
109 112
110 assert isinstance(args, list) or isinstance(args, tuple) 113 assert isinstance(args, list) or isinstance(args, tuple)
111 if self._should_log: 114 if self._should_log:
112 env_string = "" 115 env_string = ""
113 if env: 116 if env:
114 env_string = ", env=%s" % env 117 env_string = ", env=%s" % env
115 input_string = "" 118 input_string = ""
116 if input: 119 if input:
117 input_string = ", input=%s" % input 120 input_string = ", input=%s" % input
118 _log.info("MOCK run_command: %s, cwd=%s%s%s", args, cwd, env_string, input_string) 121 _log.info("MOCK run_command: %s, cwd=%s%s%s", args, cwd, env_string, input_string)
119 output = "MOCK output of child process"
120 122
121 if self._should_throw_when_run.intersection(args): 123 if self._should_throw_when_run.intersection(args):
122 raise ScriptError("Exception for %s" % args, output="MOCK command ou tput") 124 raise ScriptError("Exception for %s" % args, output="MOCK command ou tput")
123 125
124 if self._should_throw: 126 if self._should_throw:
125 raise ScriptError("MOCK ScriptError", output=output) 127 raise ScriptError("MOCK ScriptError", output=self._output)
126 128
127 if return_exit_code and self._should_return_zero_when_run.intersection(a rgs): 129 if return_exit_code and self._should_return_zero_when_run.intersection(a rgs):
128 return 0 130 return 0
129 131
130 return output 132 return self._output
131 133
132 def cpu_count(self): 134 def cpu_count(self):
133 return 2 135 return 2
134 136
135 def kill_all(self, process_name): 137 def kill_all(self, process_name):
136 pass 138 pass
137 139
138 def kill_process(self, pid): 140 def kill_process(self, pid):
139 pass 141 pass
140 142
141 def popen(self, args, cwd=None, env=None, **kwargs): 143 def popen(self, args, cwd=None, env=None, **kwargs):
142 assert all(isinstance(arg, basestring) for arg in args) 144 assert all(isinstance(arg, basestring) for arg in args)
143 self.calls.append(args) 145 self.calls.append(args)
144 if self._should_log: 146 if self._should_log:
145 cwd_string = "" 147 cwd_string = ""
146 if cwd: 148 if cwd:
147 cwd_string = ", cwd=%s" % cwd 149 cwd_string = ", cwd=%s" % cwd
148 env_string = "" 150 env_string = ""
149 if env: 151 if env:
150 env_string = ", env=%s" % env 152 env_string = ", env=%s" % env
151 _log.info("MOCK popen: %s%s%s", args, cwd_string, env_string) 153 _log.info("MOCK popen: %s%s%s", args, cwd_string, env_string)
152 if not self._proc: 154 if not self._proc:
153 self._proc = MockProcess() 155 self._proc = MockProcess(self._output)
154 return self._proc 156 return self._proc
155 157
156 def call(self, args, **kwargs): 158 def call(self, args, **kwargs):
157 assert all(isinstance(arg, basestring) for arg in args) 159 assert all(isinstance(arg, basestring) for arg in args)
158 self.calls.append(args) 160 self.calls.append(args)
159 _log.info('Mock call: %s', args) 161 _log.info('Mock call: %s', args)
160 162
161 def run_in_parallel(self, commands): 163 def run_in_parallel(self, commands):
162 assert len(commands) 164 assert len(commands)
163 165
(...skipping 12 matching lines...) Expand all
176 return map(thunk, arglist) 178 return map(thunk, arglist)
177 179
178 def process_dump(self): 180 def process_dump(self):
179 return [] 181 return []
180 182
181 183
182 class MockExecutive2(MockExecutive): 184 class MockExecutive2(MockExecutive):
183 """MockExecutive2 is like MockExecutive except it doesn't log anything.""" 185 """MockExecutive2 is like MockExecutive except it doesn't log anything."""
184 186
185 def __init__(self, output='', exit_code=0, exception=None, run_command_fn=No ne, stderr=''): 187 def __init__(self, output='', exit_code=0, exception=None, run_command_fn=No ne, stderr=''):
188 super(MockExecutive2, self).__init__()
186 self._output = output 189 self._output = output
187 self._stderr = stderr 190 self._stderr = stderr
188 self._exit_code = exit_code 191 self._exit_code = exit_code
189 self._exception = exception 192 self._exception = exception
190 self._run_command_fn = run_command_fn 193 self._run_command_fn = run_command_fn
191 self.calls = []
192 194
193 def run_command(self, 195 def run_command(self,
194 args, 196 args,
195 cwd=None, 197 cwd=None,
196 input=None, 198 input=None,
197 error_handler=None, 199 error_handler=None,
198 return_exit_code=False, 200 return_exit_code=False,
199 return_stderr=True, 201 return_stderr=True,
200 decode_output=False, 202 decode_output=False,
201 env=None, 203 env=None,
202 debug_logging=False): 204 debug_logging=False):
203 self.calls.append(args) 205 self.calls.append(args)
204 assert isinstance(args, list) or isinstance(args, tuple) 206 assert isinstance(args, list) or isinstance(args, tuple)
205 assert all(isinstance(arg, basestring) for arg in args) 207 assert all(isinstance(arg, basestring) for arg in args)
206 if self._exception: 208 if self._exception:
207 raise self._exception # pylint: disable=E0702 209 raise self._exception # pylint: disable=E0702
208 if self._run_command_fn: 210 if self._run_command_fn:
209 return self._run_command_fn(args) 211 return self._run_command_fn(args)
210 if return_exit_code: 212 if return_exit_code:
211 return self._exit_code 213 return self._exit_code
212 if self._exit_code and error_handler: 214 if self._exit_code and error_handler:
213 script_error = ScriptError(script_args=args, exit_code=self._exit_co de, output=self._output) 215 script_error = ScriptError(script_args=args, exit_code=self._exit_co de, output=self._output)
214 error_handler(script_error) 216 error_handler(script_error)
215 if return_stderr: 217 if return_stderr:
216 return self._output + self._stderr 218 return self._output + self._stderr
217 return self._output 219 return self._output
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/deps_updater.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698