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

Side by Side Diff: client/tests/run_isolated_test.py

Issue 2440353004: Return specific files, not just those in $(ISOLATED_OUTDIR) (Closed)
Patch Set: Return files specified by --output in addition to those in output dir 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
« client/run_isolated.py ('K') | « client/run_isolated.py ('k') | no next file » | 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 2013 The LUCI Authors. All rights reserved. 2 # Copyright 2013 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 # pylint: disable=R0201 6 # pylint: disable=R0201
7 7
8 import StringIO 8 import StringIO
9 import base64 9 import base64
10 import functools 10 import functools
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 make_tree_call.append(i) 203 make_tree_call.append(i)
204 for i in ('make_tree_read_only', 'make_tree_files_read_only', 204 for i in ('make_tree_read_only', 'make_tree_files_read_only',
205 'make_tree_deleteable', 'make_tree_writeable'): 205 'make_tree_deleteable', 'make_tree_writeable'):
206 self.mock(file_path, i, functools.partial(add, i)) 206 self.mock(file_path, i, functools.partial(add, i))
207 207
208 ret = run_isolated.run_tha_test( 208 ret = run_isolated.run_tha_test(
209 command, 209 command,
210 isolated_hash, 210 isolated_hash,
211 StorageFake(files), 211 StorageFake(files),
212 isolateserver.MemoryCache(), 212 isolateserver.MemoryCache(),
213 None,
213 False, 214 False,
214 None, 215 None,
215 None, 216 None,
216 None, 217 None,
217 None, 218 None,
218 None, 219 None,
219 None, 220 None,
220 lambda run_dir: None, 221 lambda run_dir: None,
221 False) 222 False)
222 self.assertEqual(0, ret) 223 self.assertEqual(0, ret)
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 server.add_content('default-store', script) 488 server.add_content('default-store', script)
488 server.add_content('default-store', isolated_data) 489 server.add_content('default-store', isolated_data)
489 store = isolateserver.get_storage(server.url, 'default-store') 490 store = isolateserver.get_storage(server.url, 'default-store')
490 491
491 self.mock(sys, 'stdout', StringIO.StringIO()) 492 self.mock(sys, 'stdout', StringIO.StringIO())
492 ret = run_isolated.run_tha_test( 493 ret = run_isolated.run_tha_test(
493 None, 494 None,
494 isolated_hash, 495 isolated_hash,
495 store, 496 store,
496 isolateserver.MemoryCache(), 497 isolateserver.MemoryCache(),
498 None,
497 False, 499 False,
498 None, 500 None,
499 None, 501 None,
500 None, 502 None,
501 None, 503 None,
502 None, 504 None,
503 None, 505 None,
504 lambda run_dir: None, 506 lambda run_dir: None,
505 False) 507 False)
506 self.assertEqual(0, ret) 508 self.assertEqual(0, ret)
(...skipping 25 matching lines...) Expand all
532 '[run_isolated_out_hack]', 534 '[run_isolated_out_hack]',
533 '{"hash":"%s","namespace":"default-store","storage":%s}' % ( 535 '{"hash":"%s","namespace":"default-store","storage":%s}' % (
534 uploaded_hash, json.dumps(server.url)), 536 uploaded_hash, json.dumps(server.url)),
535 '[/run_isolated_out_hack]' 537 '[/run_isolated_out_hack]'
536 ]) + '\n' 538 ]) + '\n'
537 self.assertEqual(expected, sys.stdout.getvalue()) 539 self.assertEqual(expected, sys.stdout.getvalue())
538 finally: 540 finally:
539 server.close() 541 server.close()
540 542
541 543
544 # Like RunIsolatedTestRun, but ensures that specific output files
545 # (as opposed to anything in ISOLATED_OUT_DIR) are returned.
546 class RunIsolatedTestOutputFiles(RunIsolatedTestBase):
547 def test_output(self):
548 # Starts a full isolate server mock and have run_tha_test() uploads results
549 # back after the task completed.
550 server = isolateserver_mock.MockIsolateServer()
551 try:
552 script = (
553 'import sys\n'
554 'open(sys.argv[1], "w").write("bar")\n'
555 'open(sys.argv[2], "w").write("baz")\n')
556 script_hash = isolateserver_mock.hash_content(script)
557 isolated = {
558 'algo': 'sha-1',
559 'command': ['cmd.py', 'foo', 'foodir/foo2'],
560 'files': {
561 'cmd.py': {
562 'h': script_hash,
563 'm': 0700,
564 's': len(script),
565 },
566 },
567 'version': isolated_format.ISOLATED_FILE_VERSION,
568 }
569 if sys.platform == 'win32':
570 isolated['files']['cmd.py'].pop('m')
571 isolated_data = json_dumps(isolated)
572 isolated_hash = isolateserver_mock.hash_content(isolated_data)
573 server.add_content('default-store', script)
574 server.add_content('default-store', isolated_data)
575 store = isolateserver.get_storage(server.url, 'default-store')
576
577 self.mock(sys, 'stdout', StringIO.StringIO())
578 ret = run_isolated.run_tha_test(
579 None,
580 isolated_hash,
581 store,
582 isolateserver.MemoryCache(),
583 ['foo', 'foodir/foo2'],
584 False,
585 None,
586 None,
587 None,
588 None,
589 None,
590 None,
591 lambda run_dir: None,
592 False)
593 self.assertEqual(0, ret)
594
595 # It uploaded back. Assert the store has a new item containing foo.
596 hashes = {isolated_hash, script_hash}
597 foo_output_hash = isolateserver_mock.hash_content('bar')
598 foo2_output_hash = isolateserver_mock.hash_content('baz')
599 hashes.add(foo_output_hash)
600 hashes.add(foo2_output_hash)
601 isolated = {
602 'algo': 'sha-1',
603 'files': {
604 'foo': {
605 'h': foo_output_hash,
606 # TODO(maruel): Handle umask.
607 'm': 0640,
608 's': 3,
609 },
610 'foodir/foo2': {
611 'h': foo2_output_hash,
612 # TODO(maruel): Handle umask.
613 'm': 0640,
614 's': 3,
615 },
616 },
617 'version': isolated_format.ISOLATED_FILE_VERSION,
618 }
619 if sys.platform == 'win32':
620 isolated['files']['foo'].pop('m')
621 isolated['files']['foodir/foo2'].pop('m')
622 uploaded = json_dumps(isolated)
623 uploaded_hash = isolateserver_mock.hash_content(uploaded)
624 hashes.add(uploaded_hash)
625 self.assertEqual(hashes, set(server.contents['default-store']))
626
627 expected = ''.join([
628 '[run_isolated_out_hack]',
629 '{"hash":"%s","namespace":"default-store","storage":%s}' % (
630 uploaded_hash, json.dumps(server.url)),
631 '[/run_isolated_out_hack]'
632 ]) + '\n'
633 self.assertEqual(expected, sys.stdout.getvalue())
634 finally:
635 server.close()
636
637
542 class RunIsolatedJsonTest(RunIsolatedTestBase): 638 class RunIsolatedJsonTest(RunIsolatedTestBase):
543 # Similar to RunIsolatedTest but adds the hacks to process ISOLATED_OUTDIR to 639 # Similar to RunIsolatedTest but adds the hacks to process ISOLATED_OUTDIR to
544 # generate a json result file. 640 # generate a json result file.
545 def setUp(self): 641 def setUp(self):
546 super(RunIsolatedJsonTest, self).setUp() 642 super(RunIsolatedJsonTest, self).setUp()
547 self.popen_calls = [] 643 self.popen_calls = []
548 644
549 # pylint: disable=no-self-argument 645 # pylint: disable=no-self-argument
550 class Popen(object): 646 class Popen(object):
551 def __init__(self2, args, **kwargs): 647 def __init__(self2, args, **kwargs):
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 self.assertEqual(expected, actual) 745 self.assertEqual(expected, actual)
650 746
651 747
652 if __name__ == '__main__': 748 if __name__ == '__main__':
653 fix_encoding.fix_encoding() 749 fix_encoding.fix_encoding()
654 if '-v' in sys.argv: 750 if '-v' in sys.argv:
655 unittest.TestCase.maxDiff = None 751 unittest.TestCase.maxDiff = None
656 logging.basicConfig( 752 logging.basicConfig(
657 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 753 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
658 unittest.main() 754 unittest.main()
OLDNEW
« client/run_isolated.py ('K') | « client/run_isolated.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698