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

Side by Side Diff: tools/isolate/isolate_smoke_test.py

Issue 10080013: Makes the code simpler by automatically deducing the root directory to use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now completely working on windows Created 8 years, 8 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 | « tools/isolate/isolate.py ('k') | tools/isolate/isolate_test.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 cStringIO 6 import cStringIO
7 import hashlib 7 import hashlib
8 import json 8 import json
9 import logging 9 import logging
10 import os 10 import os
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 v[u'timestamp'] = int(round(filestats.st_mtime)) 112 v[u'timestamp'] = int(round(filestats.st_mtime))
113 113
114 if self.LEVEL >= isolate.WITH_HASH: 114 if self.LEVEL >= isolate.WITH_HASH:
115 for filename in files: 115 for filename in files:
116 # Calculate our hash. 116 # Calculate our hash.
117 h = hashlib.sha1() 117 h = hashlib.sha1()
118 h.update(open(os.path.join(root_dir, filename), 'rb').read()) 118 h.update(open(os.path.join(root_dir, filename), 'rb').read())
119 files[filename][u'sha-1'] = unicode(h.hexdigest()) 119 files[filename][u'sha-1'] = unicode(h.hexdigest())
120 return files 120 return files
121 121
122 def _expected_result(self, args, read_only): 122 def _expected_result(self, args, read_only, extra_vars=None):
123 """Verifies self.result contains the expected data.""" 123 """Verifies self.result contains the expected data."""
124 flavor = isolate.trace_inputs.get_flavor()
124 expected = { 125 expected = {
125 u'files': self._gen_files(read_only), 126 u'files': self._gen_files(read_only),
127 u'read_only': read_only,
126 u'relative_cwd': unicode(RELATIVE_CWD[self.case()]), 128 u'relative_cwd': unicode(RELATIVE_CWD[self.case()]),
127 u'read_only': read_only, 129 u'resultdir': os.path.dirname(self.result),
130 u'resultfile': self.result,
131 u'variables': {
132 u'EXECUTABLE_SUFFIX': '.exe' if flavor == 'win' else '',
133 u'OS': unicode(flavor),
134 },
128 } 135 }
136 expected['variables'].update(extra_vars or {})
129 if args: 137 if args:
130 expected[u'command'] = [u'python'] + [unicode(x) for x in args] 138 expected[u'command'] = [u'python'] + [unicode(x) for x in args]
131 else: 139 else:
132 expected[u'command'] = [] 140 expected[u'command'] = []
133 141
134 self.assertEquals(expected, json.load(open(self.result, 'rb'))) 142 self.assertEquals(expected, json.load(open(self.result, 'rb')))
135 return expected 143 return expected
136 144
137 def _expect_no_result(self): 145 def _expect_no_result(self):
138 self.assertFalse(os.path.exists(self.result)) 146 self.assertFalse(os.path.exists(self.result))
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 self._expected_result([], None) 273 self._expected_result([], None)
266 274
267 def test_touch_root(self): 275 def test_touch_root(self):
268 self._execute('check', 'touch_root.isolate', [], False) 276 self._execute('check', 'touch_root.isolate', [], False)
269 self._expect_no_tree() 277 self._expect_no_tree()
270 self._expected_result(['touch_root.py'], None) 278 self._expected_result(['touch_root.py'], None)
271 279
272 def test_with_flag(self): 280 def test_with_flag(self):
273 self._execute('check', 'with_flag.isolate', ['-V', 'FLAG', 'gyp'], False) 281 self._execute('check', 'with_flag.isolate', ['-V', 'FLAG', 'gyp'], False)
274 self._expect_no_tree() 282 self._expect_no_tree()
275 self._expected_result(['with_flag.py', 'gyp'], None) 283 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'})
276 284
277 285
278 class Isolate_hashtable(IsolateBase): 286 class Isolate_hashtable(IsolateBase):
279 LEVEL = isolate.WITH_HASH 287 LEVEL = isolate.WITH_HASH
280 288
281 def _expected_hash_tree(self): 289 def _expected_hash_tree(self):
282 """Verifies the files written in the temporary directory.""" 290 """Verifies the files written in the temporary directory."""
283 expected = [v['sha-1'] for v in self._gen_files(False).itervalues()] 291 expected = [v['sha-1'] for v in self._gen_files(False).itervalues()]
284 self.assertEquals(sorted(expected), self._result_tree()) 292 self.assertEquals(sorted(expected), self._result_tree())
285 293
(...skipping 27 matching lines...) Expand all
313 321
314 def test_touch_root(self): 322 def test_touch_root(self):
315 self._execute('hashtable', 'touch_root.isolate', [], False) 323 self._execute('hashtable', 'touch_root.isolate', [], False)
316 self._expected_hash_tree() 324 self._expected_hash_tree()
317 self._expected_result(['touch_root.py'], None) 325 self._expected_result(['touch_root.py'], None)
318 326
319 def test_with_flag(self): 327 def test_with_flag(self):
320 self._execute( 328 self._execute(
321 'hashtable', 'with_flag.isolate', ['-V', 'FLAG', 'gyp'], False) 329 'hashtable', 'with_flag.isolate', ['-V', 'FLAG', 'gyp'], False)
322 self._expected_hash_tree() 330 self._expected_hash_tree()
323 self._expected_result(['with_flag.py', 'gyp'], None) 331 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'})
324 332
325 333
326 class Isolate_remap(IsolateBase): 334 class Isolate_remap(IsolateBase):
327 LEVEL = isolate.STATS_ONLY 335 LEVEL = isolate.STATS_ONLY
328 336
329 def test_fail(self): 337 def test_fail(self):
330 self._execute('remap', 'fail.isolate', [], False) 338 self._execute('remap', 'fail.isolate', [], False)
331 self._expected_tree() 339 self._expected_tree()
332 self._expected_result(['fail.py'], None) 340 self._expected_result(['fail.py'], None)
333 341
(...skipping 21 matching lines...) Expand all
355 self._expected_result([], None) 363 self._expected_result([], None)
356 364
357 def test_touch_root(self): 365 def test_touch_root(self):
358 self._execute('remap', 'touch_root.isolate', [], False) 366 self._execute('remap', 'touch_root.isolate', [], False)
359 self._expected_tree() 367 self._expected_tree()
360 self._expected_result(['touch_root.py'], None) 368 self._expected_result(['touch_root.py'], None)
361 369
362 def test_with_flag(self): 370 def test_with_flag(self):
363 self._execute('remap', 'with_flag.isolate', ['-V', 'FLAG', 'gyp'], False) 371 self._execute('remap', 'with_flag.isolate', ['-V', 'FLAG', 'gyp'], False)
364 self._expected_tree() 372 self._expected_tree()
365 self._expected_result(['with_flag.py', 'gyp'], None) 373 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'})
366 374
367 375
368 class Isolate_run(IsolateBase): 376 class Isolate_run(IsolateBase):
369 LEVEL = isolate.STATS_ONLY 377 LEVEL = isolate.STATS_ONLY
370 378
371 def _expect_empty_tree(self): 379 def _expect_empty_tree(self):
372 self.assertEquals([], self._result_tree()) 380 self.assertEquals([], self._result_tree())
373 381
374 def test_fail(self): 382 def test_fail(self):
375 try: 383 try:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 417
410 def test_touch_root(self): 418 def test_touch_root(self):
411 self._execute('run', 'touch_root.isolate', [], False) 419 self._execute('run', 'touch_root.isolate', [], False)
412 self._expect_empty_tree() 420 self._expect_empty_tree()
413 self._expected_result(['touch_root.py'], None) 421 self._expected_result(['touch_root.py'], None)
414 422
415 def test_with_flag(self): 423 def test_with_flag(self):
416 self._execute('run', 'with_flag.isolate', ['-V', 'FLAG', 'run'], False) 424 self._execute('run', 'with_flag.isolate', ['-V', 'FLAG', 'run'], False)
417 # Not sure about the empty tree, should be deleted. 425 # Not sure about the empty tree, should be deleted.
418 self._expect_empty_tree() 426 self._expect_empty_tree()
419 self._expected_result(['with_flag.py', 'run'], None) 427 self._expected_result(['with_flag.py', 'run'], None, {u'FLAG': u'run'})
420 428
421 429
422 class Isolate_trace(IsolateBase): 430 class Isolate_trace(IsolateBase):
423 LEVEL = isolate.STATS_ONLY 431 LEVEL = isolate.STATS_ONLY
424 432
425 @staticmethod 433 @staticmethod
426 def _to_string(values): 434 def _to_string(values):
427 buf = cStringIO.StringIO() 435 buf = cStringIO.StringIO()
428 isolate.trace_inputs.pretty_print(values, buf) 436 isolate.trace_inputs.pretty_print(values, buf)
429 return buf.getvalue() 437 return buf.getvalue()
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 }, 497 },
490 }], 498 }],
491 ], 499 ],
492 } 500 }
493 self.assertEquals(self._to_string(expected), out) 501 self.assertEquals(self._to_string(expected), out)
494 502
495 def test_with_flag(self): 503 def test_with_flag(self):
496 out = self._execute( 504 out = self._execute(
497 'trace', 'with_flag.isolate', ['-V', 'FLAG', 'trace'], True) 505 'trace', 'with_flag.isolate', ['-V', 'FLAG', 'trace'], True)
498 self._expect_no_tree() 506 self._expect_no_tree()
499 self._expected_result(['with_flag.py', 'trace'], None) 507 self._expected_result(['with_flag.py', 'trace'], None, {u'FLAG': u'trace'})
500 expected = { 508 expected = {
501 'conditions': [ 509 'conditions': [
502 ['OS=="%s"' % isolate.trace_inputs.get_flavor(), { 510 ['OS=="%s"' % isolate.trace_inputs.get_flavor(), {
503 'variables': { 511 'variables': {
504 isolate.trace_inputs.KEY_TRACKED: [ 512 isolate.trace_inputs.KEY_TRACKED: [
505 'with_flag.py', 513 'with_flag.py',
506 ], 514 ],
507 isolate.trace_inputs.KEY_UNTRACKED: [ 515 isolate.trace_inputs.KEY_UNTRACKED: [
508 'files1/', 516 'files1/',
509 ], 517 ],
510 }, 518 },
511 }], 519 }],
512 ], 520 ],
513 } 521 }
514 self.assertEquals(self._to_string(expected), out) 522 self.assertEquals(self._to_string(expected), out)
515 523
516 524
517 525
518 if __name__ == '__main__': 526 if __name__ == '__main__':
519 VERBOSE = '-v' in sys.argv 527 VERBOSE = '-v' in sys.argv
520 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 528 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
521 unittest.main() 529 unittest.main()
OLDNEW
« no previous file with comments | « tools/isolate/isolate.py ('k') | tools/isolate/isolate_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698