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

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py

Issue 546133003: Reformat webkitpy.layout_tests w/ format-webkitpy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 def setup_environ_for_server(self, server_name): 131 def setup_environ_for_server(self, server_name):
132 env = self.__delegate.setup_environ_for_server() 132 env = self.__delegate.setup_environ_for_server()
133 # We need to propagate PATH down so the python code can find the checkou t. 133 # We need to propagate PATH down so the python code can find the checkou t.
134 env['PATH'] = os.environ['PATH'] 134 env['PATH'] = os.environ['PATH']
135 return env 135 return env
136 136
137 def lookup_virtual_test_args(self, test_name): 137 def lookup_virtual_test_args(self, test_name):
138 suite = self.__delegate.lookup_virtual_suite(test_name) 138 suite = self.__delegate.lookup_virtual_suite(test_name)
139 return suite.args + ['--virtual-test-suite-name', suite.name, '--virtual -test-suite-base', suite.base] 139 return suite.args + ['--virtual-test-suite-name', suite.name, '--virtual -test-suite-base', suite.base]
140 140
141
141 def main(argv, host, stdin, stdout, stderr): 142 def main(argv, host, stdin, stdout, stderr):
142 """Run the tests.""" 143 """Run the tests."""
143 144
144 options, args = parse_options(argv) 145 options, args = parse_options(argv)
145 drt = MockDRT(options, args, host, stdin, stdout, stderr) 146 drt = MockDRT(options, args, host, stdin, stdout, stderr)
146 return drt.run() 147 return drt.run()
147 148
148 149
149 def parse_options(argv): 150 def parse_options(argv):
150 # We do custom arg parsing instead of using the optparse module 151 # We do custom arg parsing instead of using the optparse module
151 # because we don't want to have to list every command line flag DRT 152 # because we don't want to have to list every command line flag DRT
152 # accepts, and optparse complains about unrecognized flags. 153 # accepts, and optparse complains about unrecognized flags.
153 154
154 def get_arg(arg_name): 155 def get_arg(arg_name):
155 if arg_name in argv: 156 if arg_name in argv:
156 index = argv.index(arg_name) 157 index = argv.index(arg_name)
157 return argv[index + 1] 158 return argv[index + 1]
158 return None 159 return None
159 160
160 options = optparse.Values({ 161 options = optparse.Values({
161 'actual_directory': get_arg('--actual-directory'), 162 'actual_directory': get_arg('--actual-directory'),
162 'platform': get_arg('--platform'), 163 'platform': get_arg('--platform'),
163 'virtual_test_suite_base': get_arg('--virtual-test-suite-base'), 164 'virtual_test_suite_base': get_arg('--virtual-test-suite-base'),
164 'virtual_test_suite_name': get_arg('--virtual-test-suite-name'), 165 'virtual_test_suite_name': get_arg('--virtual-test-suite-name'),
165 }) 166 })
166 return (options, argv) 167 return (options, argv)
167 168
168 169
169 class MockDRT(object): 170 class MockDRT(object):
171
170 def __init__(self, options, args, host, stdin, stdout, stderr): 172 def __init__(self, options, args, host, stdin, stdout, stderr):
171 self._options = options 173 self._options = options
172 self._args = args 174 self._args = args
173 self._host = host 175 self._host = host
174 self._stdout = stdout 176 self._stdout = stdout
175 self._stdin = stdin 177 self._stdin = stdin
176 self._stderr = stderr 178 self._stderr = stderr
177 179
178 port_name = None 180 port_name = None
179 if options.platform: 181 if options.platform:
(...skipping 29 matching lines...) Expand all
209 if uri.startswith('http://') or uri.startswith('https://'): 211 if uri.startswith('http://') or uri.startswith('https://'):
210 test_name = self._driver.uri_to_test(uri) 212 test_name = self._driver.uri_to_test(uri)
211 else: 213 else:
212 test_name = self._port.relative_test_filename(uri) 214 test_name = self._port.relative_test_filename(uri)
213 215
214 return DriverInput(test_name, 0, checksum, should_run_pixel_tests, args= []) 216 return DriverInput(test_name, 0, checksum, should_run_pixel_tests, args= [])
215 217
216 def output_for_test(self, test_input, is_reftest): 218 def output_for_test(self, test_input, is_reftest):
217 port = self._port 219 port = self._port
218 if self._options.virtual_test_suite_name: 220 if self._options.virtual_test_suite_name:
219 test_input.test_name = test_input.test_name.replace(self._options.vi rtual_test_suite_base, self._options.virtual_test_suite_name) 221 test_input.test_name = test_input.test_name.replace(
222 self._options.virtual_test_suite_base,
223 self._options.virtual_test_suite_name)
220 actual_text = port.expected_text(test_input.test_name) 224 actual_text = port.expected_text(test_input.test_name)
221 actual_audio = port.expected_audio(test_input.test_name) 225 actual_audio = port.expected_audio(test_input.test_name)
222 actual_image = None 226 actual_image = None
223 actual_checksum = None 227 actual_checksum = None
224 if is_reftest: 228 if is_reftest:
225 # Make up some output for reftests. 229 # Make up some output for reftests.
226 actual_text = 'reference text\n' 230 actual_text = 'reference text\n'
227 actual_checksum = 'mock-checksum' 231 actual_checksum = 'mock-checksum'
228 actual_image = 'blank' 232 actual_image = 'blank'
229 if test_input.test_name.endswith('-mismatch.html'): 233 if test_input.test_name.endswith('-mismatch.html'):
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 self._stdout.write('#EOF\n') 281 self._stdout.write('#EOF\n')
278 self._stdout.flush() 282 self._stdout.flush()
279 self._stderr.write('#EOF\n') 283 self._stderr.write('#EOF\n')
280 self._stderr.flush() 284 self._stderr.flush()
281 285
282 286
283 if __name__ == '__main__': 287 if __name__ == '__main__':
284 # Note that the Mock in MockDRT refers to the fact that it is emulating a 288 # Note that the Mock in MockDRT refers to the fact that it is emulating a
285 # real DRT, and as such, it needs access to a real SystemHost, not a MockSys temHost. 289 # real DRT, and as such, it needs access to a real SystemHost, not a MockSys temHost.
286 sys.exit(main(sys.argv[1:], SystemHost(), sys.stdin, sys.stdout, sys.stderr) ) 290 sys.exit(main(sys.argv[1:], SystemHost(), sys.stdin, sys.stdout, sys.stderr) )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698