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

Side by Side Diff: app_test.py

Issue 11535002: chromium-build app now renders console from stored rows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chromium-build
Patch Set: Add test_parse_master_utf8 Created 7 years, 11 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
« no previous file with comments | « app.py ('k') | handler.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import ast
6 import datetime 7 import datetime
7 import os 8 import os
8 import unittest 9 import unittest
9 10
10 import app 11 import app
11 12
12 13
13 TEST_DIR = os.path.join(os.path.dirname(__file__), 'tests') 14 TEST_DIR = os.path.join(os.path.dirname(__file__), 'tests')
14 15
15 16
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 self.save_page(localpath='chromium/sheriff_perf.js', 198 self.save_page(localpath='chromium/sheriff_perf.js',
198 content='document.write(\'sheriff5\')') 199 content='document.write(\'sheriff5\')')
199 self.save_page(localpath='chromium/sheriff_cros_mtv.js', 200 self.save_page(localpath='chromium/sheriff_cros_mtv.js',
200 content='document.write(\'sheriff6, sheriff7\')') 201 content='document.write(\'sheriff6, sheriff7\')')
201 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js', 202 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js',
202 content='document.write(\'sheriff8\')') 203 content='document.write(\'sheriff8\')')
203 input_console = self._load_content(test_dir, 'console-input.html') 204 input_console = self._load_content(test_dir, 'console-input.html')
204 expected_console = self._load_content(test_dir, 'console-expected.html') 205 expected_console = self._load_content(test_dir, 'console-expected.html')
205 page_data = {'content': input_console} 206 page_data = {'content': input_console}
206 actual_console = app.console_handler( 207 actual_console = app.console_handler(
207 _unquoted_localpath='chromium/console', 208 unquoted_localpath='chromium/console',
208 remoteurl='http://build.chromium.org/p/chromium/console', 209 remoteurl='http://build.chromium.org/p/chromium/console',
209 page_data=page_data) 210 page_data=page_data)
210 # Uncomment if deeper inspection is needed of the returned console. 211 # Uncomment if deeper inspection is needed of the returned console.
211 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh: 212 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh:
212 # fh.write(actual_console['content']) 213 # fh.write(actual_console['content'])
213 self.assertEquals(expected_console, actual_console['content'], 214 self.assertEquals(expected_console, actual_console['content'],
214 'Unexpected console output found') 215 'Unexpected console output found')
215 216
216 def test_console_handler_utf8(self): 217 def test_console_handler_utf8(self):
217 test_dir = os.path.join(TEST_DIR, 'test_console_handler_utf8') 218 test_dir = os.path.join(TEST_DIR, 'test_console_handler_utf8')
218 self.save_page(localpath='chromium/sheriff.js', 219 self.save_page(localpath='chromium/sheriff.js',
219 content='document.write(\'sheriff1\')') 220 content='document.write(\'sheriff1\')')
220 self.save_page(localpath='chromium/sheriff_webkit.js', 221 self.save_page(localpath='chromium/sheriff_webkit.js',
221 content='document.write(\'sheriff2\')') 222 content='document.write(\'sheriff2\')')
222 self.save_page(localpath='chromium/sheriff_memory.js', 223 self.save_page(localpath='chromium/sheriff_memory.js',
223 content='document.write(\'sheriff3\')') 224 content='document.write(\'sheriff3\')')
224 self.save_page(localpath='chromium/sheriff_nacl.js', 225 self.save_page(localpath='chromium/sheriff_nacl.js',
225 content='document.write(\'sheriff4\')') 226 content='document.write(\'sheriff4\')')
226 self.save_page(localpath='chromium/sheriff_perf.js', 227 self.save_page(localpath='chromium/sheriff_perf.js',
227 content='document.write(\'sheriff5\')') 228 content='document.write(\'sheriff5\')')
228 self.save_page(localpath='chromium/sheriff_cros_mtv.js', 229 self.save_page(localpath='chromium/sheriff_cros_mtv.js',
229 content='document.write(\'sheriff6, sheriff7\')') 230 content='document.write(\'sheriff6, sheriff7\')')
230 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js', 231 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js',
231 content='document.write(\'sheriff8\')') 232 content='document.write(\'sheriff8\')')
232 input_console = self._load_content(test_dir, 'console-input.html') 233 input_console = self._load_content(test_dir, 'console-input.html')
233 expected_console = self._load_content(test_dir, 'console-expected.html') 234 expected_console = self._load_content(test_dir, 'console-expected.html')
234 page_data = {'content': input_console} 235 page_data = {'content': input_console}
235 actual_console = app.console_handler( 236 actual_console = app.console_handler(
236 _unquoted_localpath='chromium/console', 237 unquoted_localpath='chromium/console',
237 remoteurl='http://build.chromium.org/p/chromium/console', 238 remoteurl='http://build.chromium.org/p/chromium/console',
238 page_data=page_data) 239 page_data=page_data)
239 # Uncomment if deeper inspection is needed of the returned console. 240 # Uncomment if deeper inspection is needed of the returned console.
240 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh: 241 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh:
241 # fh.write(actual_console['content']) 242 # fh.write(actual_console['content'])
242 self.assertEquals(expected_console, actual_console['content'], 243 self.assertEquals(expected_console, actual_console['content'],
243 'Unexpected console output found') 244 'Unexpected console output found')
244 245
245 def test_parse_master(self): 246 def test_parse_master(self):
246 test_dir = os.path.join(TEST_DIR, 'test_parse_master') 247 test_dir = os.path.join(TEST_DIR, 'test_parse_master')
247 expected_rev = self._load_content(test_dir, 'expected-rev.html').strip() 248 expected_rev = self._load_content(test_dir, 'expected-rev.html').strip()
248 expected_name = self._load_content(test_dir, 'expected-name.html').strip() 249 expected_name = self._load_content(test_dir, 'expected-name.html').strip()
249 expected_status = self._load_content(test_dir, 250 expected_status = self._load_content(test_dir,
250 'expected-status.html').strip() 251 'expected-status.html').strip()
251 expected_comment = self._load_content(test_dir, 252 expected_comment = self._load_content(test_dir,
252 'expected-comment.html').strip() 253 'expected-comment.html').strip()
253 expected_details = self._load_content(test_dir, 254 expected_details = self._load_content(test_dir,
254 'expected-details.html').strip() 255 'expected-details.html').strip()
255 expected_summary = self._load_content(test_dir, 256 expected_summary = self._load_content(test_dir,
256 'expected-summary.html').strip() 257 'expected-summary.html').strip()
257 print(expected_summary)
258 print("\n\n\n\n")
259 input_console = self._load_content(test_dir, 'console-input-handled.html') 258 input_console = self._load_content(test_dir, 'console-input-handled.html')
260 page_data = {'content': input_console} 259 page_data = {'content': input_console}
261 test_localpath = 'chromium/console' 260 test_localpath = 'chromium/console'
262 # Parse master returns its input, so we throw that away and access 261 # Parse master returns its input, so we throw that away and access
263 # the stored rows directly. 262 # the stored rows directly.
264 app.parse_master( 263 app.parse_master(
265 localpath=test_localpath, 264 localpath=test_localpath,
266 remoteurl='http://build.chromium.org/p/chromium/console', 265 remoteurl='http://build.chromium.org/p/chromium/console',
267 page_data=page_data) 266 page_data=page_data)
268 test_revision = '121192' 267 test_revision = '121192'
269 actual_row = app.Row.get_by_key_name(test_revision + ' ' + test_localpath) 268 actual_row = app.get_and_cache_rowdata(test_localpath + '/' + test_revision)
270 actual_row = app.db.to_dict(actual_row) 269 actual_summary = app.get_and_cache_pagedata(test_localpath + '/summary')
271 actual_summary = app.Page.get_by_key_name(test_localpath + '/summary') 270 self.assertEquals(expected_rev, actual_row['rev'],
272 actual_summary = app.db.to_dict(actual_summary)
273 print(actual_summary['content'])
274 self.assertEquals(expected_rev, actual_row['revision'],
275 'Unexpected revision number found') 271 'Unexpected revision number found')
276 self.assertEquals(expected_name, actual_row['name'], 272 self.assertEquals(expected_name, actual_row['name'],
277 'Unexpected revision author found') 273 'Unexpected revision author found')
278 self.assertEquals(expected_status, actual_row['status'], 274 self.assertEquals(expected_status, actual_row['status'],
279 'Unexpected build status found') 275 'Unexpected build status found')
280 self.assertEquals(expected_comment, actual_row['comment'], 276 self.assertEquals(expected_comment, actual_row['comment'],
281 'Unexpected commit message found') 277 'Unexpected commit message found')
282 self.assertEquals(expected_details, actual_row['details'], 278 self.assertEquals(expected_details, actual_row['details'],
283 'Unexpected build details found') 279 'Unexpected build details found')
284 self.assertEquals(expected_summary, actual_summary['content'], 280 self.assertEquals(expected_summary, actual_summary['content'],
285 'Unexpected build summary found') 281 'Unexpected build summary found')
286 282
283 def test_parse_master_utf8(self):
284 test_dir = os.path.join(TEST_DIR, 'test_parse_master_utf8')
285 expected_rev = self._load_content(test_dir, 'expected-rev.html').strip()
286 expected_name = self._load_content(test_dir, 'expected-name.html').strip()
287 expected_status = self._load_content(test_dir,
288 'expected-status.html').strip()
289 expected_comment = self._load_content(test_dir,
290 'expected-comment.html').strip()
291 expected_details = self._load_content(test_dir,
292 'expected-details.html').strip()
293 expected_summary = self._load_content(test_dir,
294 'expected-summary.html').strip()
295 input_console = self._load_content(test_dir, 'console-input-handled.html')
296 page_data = {'content': input_console}
297 test_localpath = 'chromium/console'
298 # Parse master returns its input, so we throw that away and access
299 # the stored rows directly.
300 app.parse_master(
301 localpath=test_localpath,
302 remoteurl='http://build.chromium.org/p/chromium/console',
303 page_data=page_data)
304 test_revision = '121192'
305 actual_row = app.get_and_cache_rowdata(test_localpath + '/' + test_revision)
306 actual_summary = app.get_and_cache_pagedata(test_localpath + '/summary')
307 self.assertEquals(expected_rev.decode('utf-8'), actual_row['rev'],
308 'Unexpected revision number found')
309 self.assertEquals(expected_name.decode('utf-8'), actual_row['name'],
310 'Unexpected revision author found')
311 self.assertEquals(expected_status.decode('utf-8'), actual_row['status'],
312 'Unexpected build status found')
313 self.assertEquals(expected_comment.decode('utf-8'), actual_row['comment'],
314 'Unexpected commit message found')
315 self.assertEquals(expected_details.decode('utf-8'), actual_row['details'],
316 'Unexpected build details found')
317 self.assertEquals(expected_summary.decode('utf-8'),
318 actual_summary['content'],
319 'Unexpected build summary found')
287 320
288 def test_console_merger(self): 321 def test_console_merger(self):
322 # Read in all the necessary input files.
289 test_dir = os.path.join(TEST_DIR, 'test_console_merger') 323 test_dir = os.path.join(TEST_DIR, 'test_console_merger')
290 filedata = {} 324 test_masters = ['linux', 'mac', 'win', 'memory']
291 for filename in [ 325 filenames = ['latest_rev.txt', 'surroundings_input.html']
292 'chromium_chrome_console_input.html', 326 for master in test_masters:
293 'chromium_chromiumos_console_input.html', 327 filenames += ['%s_categories_input.html' % master,
294 'chromium_main_console_input.html', 328 '%s_summary_input.html' % master,
295 'chromium_memory_console_input.html', 329 '%s_row_input.txt' % master]
296 'chromium_merged_console.html', 330 filenames.append('merged_console_output.html')
297 ]: 331 files = {}
298 filedata[filename] = self._load_content(test_dir, filename) 332 for filename in filenames:
299 self.save_page(localpath='chromium.chrome/console', 333 files[filename] = self._load_content(test_dir, filename)
300 content=filedata['chromium_chrome_console_input.html']) 334
301 self.save_page(localpath='chromium.chromiumos/console', 335 # Save the input files as the corresponding pages and rows.
302 content=filedata['chromium_chromiumos_console_input.html']) 336 test_rev = files['latest_rev.txt'].strip()
303 self.save_page(localpath='chromium.main/console', 337 app.memcache.set(key='latest_rev', value=test_rev)
304 content=filedata['chromium_main_console_input.html']) 338 self.save_page(localpath='surroundings',
305 self.save_page(localpath='chromium.memory/console', 339 content=files['surroundings_input.html'])
306 content=filedata['chromium_memory_console_input.html']) 340 for master in test_masters:
307 page_data = {'content': filedata['chromium_merged_console.html']} 341 self.save_page('chromium.%s/console/categories' % master,
342 files['%s_categories_input.html' % master])
343 self.save_page('chromium.%s/console/summary' % master,
344 files['%s_summary_input.html' % master])
345 app.save_row(ast.literal_eval(files['%s_row_input.txt' % master]),
346 'chromium.%s/console/%s' % (master, test_rev),
347 datetime.datetime.now())
348
349 # Get the expected and real output, compare.
350 self.save_page('merged_output', files['merged_console_output.html'])
308 app.console_merger( 351 app.console_merger(
309 'chromium.main/console', 352 'chromium/console', '', {},
310 'http://build.chromium.org/p/chromium/console',
311 page_data=page_data,
312 masters_to_merge=[ 353 masters_to_merge=[
313 'chromium.main', 354 'chromium.linux',
314 'chromium.chromiumos', 355 'chromium.mac',
315 'chromium.chrome', 356 'chromium.win',
316 'chromium.memory', 357 'chromium.memory',
317 ]) 358 ],
359 num_rows_to_merge=1)
318 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console') 360 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console')
319 # Uncomment if deeper inspection is needed of the returned console. 361 # Uncomment if deeper inspection is needed of the returned console.
320 # import logging 362 # import logging
321 # logging.debug('foo') 363 # logging.debug('foo')
322 # with open(os.path.join(test_dir, 'chromium_merged_console.html'), 364 # with open(os.path.join(test_dir, 'merged_console_output.html'),
323 # 'w') as fh: 365 # 'w') as fh:
324 # fh.write(actual_mergedconsole['content']) 366 # fh.write(actual_mergedconsole['content'])
325 # import code 367 # import code
326 # code.interact(local=locals()) 368 # code.interact(local=locals())
327 self.assertEquals(filedata['chromium_merged_console.html'], 369 self.assertEquals(files['merged_console_output.html'],
328 actual_mergedconsole['content'], 370 actual_mergedconsole['content'],
329 'Unexpected console output found') 371 'Unexpected console output found')
330 372
331 def test_console_merger_utf8(self): 373 def test_console_merger_splitrevs(self):
332 test_dir = os.path.join(TEST_DIR, 'test_console_merger_utf8') 374 # Read in all the necessary input files.
333 filedata = {} 375 test_dir = os.path.join(TEST_DIR, 'test_console_merger_splitrevs')
334 for filename in [ 376 test_masters = ['linux', 'mac']
335 'chromium_chrome_console_input.html', 377 filenames = ['latest_rev.txt', 'surroundings_input.html']
336 'chromium_chromiumos_console_input.html', 378 for master in test_masters:
337 'chromium_main_console_input.html', 379 filenames += ['%s_categories_input.html' % master,
338 'chromium_memory_console_input.html', 380 '%s_summary_input.html' % master,
339 'chromium_merged_console.html', 381 '%s_row_input.txt' % master]
340 ]: 382 filenames.append('merged_console_output.html')
341 filedata[filename] = self._load_content(test_dir, filename) 383 files = {}
342 self.save_page(localpath='chromium.chrome/console', 384 for filename in filenames:
343 content=filedata['chromium_chrome_console_input.html']) 385 files[filename] = self._load_content(test_dir, filename)
344 self.save_page(localpath='chromium.chromiumos/console', 386
345 content=filedata['chromium_chromiumos_console_input.html']) 387 # Save the input files as the corresponding pages and rows.
346 self.save_page(localpath='chromium.main/console', 388 test_rev = files['latest_rev.txt'].strip()
347 content=filedata['chromium_main_console_input.html']) 389 app.memcache.set(key='latest_rev', value=test_rev)
348 self.save_page(localpath='chromium.memory/console', 390 self.save_page(localpath='surroundings',
349 content=filedata['chromium_memory_console_input.html']) 391 content=files['surroundings_input.html'])
350 page_data = {'content': filedata['chromium_merged_console.html']} 392 for master in test_masters:
393 self.save_page('chromium.%s/console/categories' % master,
394 files['%s_categories_input.html' % master])
395 self.save_page('chromium.%s/console/summary' % master,
396 files['%s_summary_input.html' % master])
397 app.save_row(ast.literal_eval(files['%s_row_input.txt' % master]),
398 'chromium.%s/console/%s' % (master, test_rev),
399 datetime.datetime.now())
400
401 # Get the expected and real output, compare.
402 self.save_page('merged_output', files['merged_console_output.html'])
351 app.console_merger( 403 app.console_merger(
352 'chromium.main/console', 404 'chromium/console', '', {},
353 'http://build.chromium.org/p/chromium/console',
354 page_data=page_data,
355 masters_to_merge=[ 405 masters_to_merge=[
356 'chromium.main', 406 'chromium.linux',
357 'chromium.chromiumos', 407 'chromium.mac',
358 'chromium.chrome', 408 ],
359 'chromium.memory', 409 num_rows_to_merge=1)
360 ])
361 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console') 410 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console')
362 # Uncomment if deeper inspection is needed of the returned console. 411 # Uncomment if deeper inspection is needed of the returned console.
363 # import logging 412 # import logging
364 # logging.debug('foo') 413 # logging.debug('foo')
365 # merged_path = os.path.join(test_dir, 'chromium_merged_console.html') 414 # with open(os.path.join(test_dir, 'merged_console_output.html'),
366 # with open(merged_path, 'w') as fh:
367 # fh.write(actual_mergedconsole['content'])
368 # import code
369 # code.interact(local=locals())
370 self.assertEquals(filedata['chromium_merged_console.html'],
371 actual_mergedconsole['content'],
372 'Unexpected console output found')
373
374 def test_console_merger_splitrevs(self):
375 test_dir = os.path.join(TEST_DIR, 'test_console_merger_splitrevs')
376 filedata = {}
377 for filename in [
378 'chromium_chrome_console.html',
379 'chromium_chromiumos_console.html',
380 'chromium_console.html',
381 'chromium_memory_console.html',
382 'chromium_merged_console.html',
383 ]:
384 filedata[filename] = self._load_content(test_dir, filename)
385 self.save_page(localpath='chromium.chrome/console',
386 content=filedata['chromium_chrome_console.html'])
387 self.save_page(localpath='chromium.chromiumos/console',
388 content=filedata['chromium_chromiumos_console.html'])
389 self.save_page(localpath='chromium.main/console',
390 content=filedata['chromium_console.html'])
391 self.save_page(localpath='chromium.memory/console',
392 content=filedata['chromium_memory_console.html'])
393 page_data = {'content': filedata['chromium_merged_console.html']}
394 app.console_merger(
395 'chromium.main/console',
396 'http://build.chromium.org/p/chromium/console',
397 page_data=page_data,
398 masters_to_merge=[
399 'chromium.main',
400 'chromium.chromiumos',
401 'chromium.chrome',
402 'chromium.memory',
403 ])
404 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console')
405 # Uncomment if deeper inspection is needed of the returned console.
406 # import logging
407 # logging.debug('foo')
408 # with open(os.path.join(test_dir, 'chromium_merged_console.html'),
409 # 'w') as fh: 415 # 'w') as fh:
410 # fh.write(actual_mergedconsole['content']) 416 # fh.write(actual_mergedconsole['content'])
411 # import code 417 # import code
412 # code.interact(local=locals()) 418 # code.interact(local=locals())
413 self.assertEquals(filedata['chromium_merged_console.html'], 419 self.assertEquals(files['merged_console_output.html'],
414 actual_mergedconsole['content'], 420 actual_mergedconsole['content'],
415 'Unexpected console output found') 421 'Unexpected console output found')
416 422
417 423
418 class FetchTestCase(GaeTestCase): 424 class FetchTestCase(GaeTestCase):
419 class FakeResponse(object): 425 class FakeResponse(object):
420 status_code = 200 426 status_code = 200
421 content = None 427 content = None
422 428
423 def test_fetch_direct(self): 429 def test_fetch_direct(self):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 page = app.get_and_cache_pagedata('chromium/console') 466 page = app.get_and_cache_pagedata('chromium/console')
461 # Uncomment if deeper inspection is needed of the returned console. 467 # Uncomment if deeper inspection is needed of the returned console.
462 # with open(os.path.join(test_dir, 'expected.html'), 'w') as fh: 468 # with open(os.path.join(test_dir, 'expected.html'), 'w') as fh:
463 # fh.write(page['content']) 469 # fh.write(page['content'])
464 self.assertEquals('interface', page['body_class']) 470 self.assertEquals('interface', page['body_class'])
465 self.assertEquals(expected_content, page['content']) 471 self.assertEquals(expected_content, page['content'])
466 self.assertEquals( 472 self.assertEquals(
467 'http://build.chromium.org/p/chromium/console/../', 473 'http://build.chromium.org/p/chromium/console/../',
468 page['offsite_base']) 474 page['offsite_base'])
469 self.assertEquals('BuildBot: Chromium', page['title']) 475 self.assertEquals('BuildBot: Chromium', page['title'])
OLDNEW
« no previous file with comments | « app.py ('k') | handler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698