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

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

Issue 2440353004: Return specific files, not just those in $(ISOLATED_OUTDIR) (Closed)
Patch Set: Response to PS5 reviews 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 | « 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 make_tree_call.append(i) 205 make_tree_call.append(i)
206 for i in ('make_tree_read_only', 'make_tree_files_read_only', 206 for i in ('make_tree_read_only', 'make_tree_files_read_only',
207 'make_tree_deleteable', 'make_tree_writeable'): 207 'make_tree_deleteable', 'make_tree_writeable'):
208 self.mock(file_path, i, functools.partial(add, i)) 208 self.mock(file_path, i, functools.partial(add, i))
209 209
210 ret = run_isolated.run_tha_test( 210 ret = run_isolated.run_tha_test(
211 command, 211 command,
212 isolated_hash, 212 isolated_hash,
213 StorageFake(files), 213 StorageFake(files),
214 isolateserver.MemoryCache(), 214 isolateserver.MemoryCache(),
215 None,
215 lambda run_dir: None, 216 lambda run_dir: None,
216 False, 217 False,
217 None, 218 None,
218 None, 219 None,
219 None, 220 None,
220 None, 221 None,
221 None, 222 None,
222 None, 223 None,
223 lambda run_dir: None, 224 lambda run_dir: None,
224 False) 225 False)
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 server.add_content('default-store', script) 535 server.add_content('default-store', script)
535 server.add_content('default-store', isolated_data) 536 server.add_content('default-store', isolated_data)
536 store = isolateserver.get_storage(server.url, 'default-store') 537 store = isolateserver.get_storage(server.url, 'default-store')
537 538
538 self.mock(sys, 'stdout', StringIO.StringIO()) 539 self.mock(sys, 'stdout', StringIO.StringIO())
539 ret = run_isolated.run_tha_test( 540 ret = run_isolated.run_tha_test(
540 None, 541 None,
541 isolated_hash, 542 isolated_hash,
542 store, 543 store,
543 isolateserver.MemoryCache(), 544 isolateserver.MemoryCache(),
545 None,
544 lambda run_dir: None, 546 lambda run_dir: None,
545 False, 547 False,
546 None, 548 None,
547 None, 549 None,
548 None, 550 None,
549 None, 551 None,
550 None, 552 None,
551 None, 553 None,
552 lambda run_dir: None, 554 lambda run_dir: None,
553 False) 555 False)
(...skipping 26 matching lines...) Expand all
580 '[run_isolated_out_hack]', 582 '[run_isolated_out_hack]',
581 '{"hash":"%s","namespace":"default-store","storage":%s}' % ( 583 '{"hash":"%s","namespace":"default-store","storage":%s}' % (
582 uploaded_hash, json.dumps(server.url)), 584 uploaded_hash, json.dumps(server.url)),
583 '[/run_isolated_out_hack]' 585 '[/run_isolated_out_hack]'
584 ]) + '\n' 586 ]) + '\n'
585 self.assertEqual(expected, sys.stdout.getvalue()) 587 self.assertEqual(expected, sys.stdout.getvalue())
586 finally: 588 finally:
587 server.close() 589 server.close()
588 590
589 591
592 # Like RunIsolatedTestRun, but ensures that specific output files
593 # (as opposed to anything in $(ISOLATED_OUTDIR)) are returned.
594 class RunIsolatedTestOutputFiles(RunIsolatedTestBase):
595 def test_output(self):
596 # Starts a full isolate server mock and have run_tha_test() uploads results
597 # back after the task completed.
598 server = isolateserver_mock.MockIsolateServer()
599 try:
600 script = (
601 'import sys\n'
602 'open(sys.argv[1], "w").write("bar")\n'
603 'open(sys.argv[2], "w").write("baz")\n')
604 script_hash = isolateserver_mock.hash_content(script)
605 isolated = {
606 'algo': 'sha-1',
607 'command': ['cmd.py', 'foo', 'foodir/foo2'],
608 'files': {
609 'cmd.py': {
610 'h': script_hash,
611 'm': 0700,
612 's': len(script),
613 },
614 },
615 'version': isolated_format.ISOLATED_FILE_VERSION,
616 }
617 if sys.platform == 'win32':
618 isolated['files']['cmd.py'].pop('m')
619 isolated_data = json_dumps(isolated)
620 isolated_hash = isolateserver_mock.hash_content(isolated_data)
621 server.add_content('default-store', script)
622 server.add_content('default-store', isolated_data)
623 store = isolateserver.get_storage(server.url, 'default-store')
624
625 self.mock(sys, 'stdout', StringIO.StringIO())
626 ret = run_isolated.run_tha_test(
627 None,
628 isolated_hash,
629 store,
630 isolateserver.MemoryCache(),
631 ['foo', 'foodir/foo2'],
632 lambda run_dir: None,
633 False,
634 None,
635 None,
636 None,
637 None,
638 None,
639 None,
640 lambda run_dir: None,
641 False)
642 self.assertEqual(0, ret)
643
644 # It uploaded back. Assert the store has a new item containing foo.
645 hashes = {isolated_hash, script_hash}
646 foo_output_hash = isolateserver_mock.hash_content('bar')
647 foo2_output_hash = isolateserver_mock.hash_content('baz')
648 hashes.add(foo_output_hash)
649 hashes.add(foo2_output_hash)
650 isolated = {
651 'algo': 'sha-1',
652 'files': {
653 'foo': {
654 'h': foo_output_hash,
655 # TODO(maruel): Handle umask.
656 'm': 0640,
657 's': 3,
658 },
659 'foodir/foo2': {
660 'h': foo2_output_hash,
661 # TODO(maruel): Handle umask.
662 'm': 0640,
663 's': 3,
664 },
665 },
666 'version': isolated_format.ISOLATED_FILE_VERSION,
667 }
668 if sys.platform == 'win32':
669 isolated['files']['foo'].pop('m')
670 isolated['files']['foodir/foo2'].pop('m')
671 uploaded = json_dumps(isolated)
672 uploaded_hash = isolateserver_mock.hash_content(uploaded)
673 hashes.add(uploaded_hash)
674 self.assertEqual(hashes, set(server.contents['default-store']))
675
676 expected = ''.join([
677 '[run_isolated_out_hack]',
678 '{"hash":"%s","namespace":"default-store","storage":%s}' % (
679 uploaded_hash, json.dumps(server.url)),
680 '[/run_isolated_out_hack]'
681 ]) + '\n'
682 self.assertEqual(expected, sys.stdout.getvalue())
683 finally:
684 server.close()
685
686
590 class RunIsolatedJsonTest(RunIsolatedTestBase): 687 class RunIsolatedJsonTest(RunIsolatedTestBase):
591 # Similar to RunIsolatedTest but adds the hacks to process ISOLATED_OUTDIR to 688 # Similar to RunIsolatedTest but adds the hacks to process ISOLATED_OUTDIR to
592 # generate a json result file. 689 # generate a json result file.
593 def setUp(self): 690 def setUp(self):
594 super(RunIsolatedJsonTest, self).setUp() 691 super(RunIsolatedJsonTest, self).setUp()
595 self.popen_calls = [] 692 self.popen_calls = []
596 693
597 # pylint: disable=no-self-argument 694 # pylint: disable=no-self-argument
598 class Popen(object): 695 class Popen(object):
599 def __init__(self2, args, **kwargs): 696 def __init__(self2, args, **kwargs):
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 self.assertEqual(expected, actual) 795 self.assertEqual(expected, actual)
699 796
700 797
701 if __name__ == '__main__': 798 if __name__ == '__main__':
702 fix_encoding.fix_encoding() 799 fix_encoding.fix_encoding()
703 if '-v' in sys.argv: 800 if '-v' in sys.argv:
704 unittest.TestCase.maxDiff = None 801 unittest.TestCase.maxDiff = None
705 logging.basicConfig( 802 logging.basicConfig(
706 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 803 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
707 unittest.main() 804 unittest.main()
OLDNEW
« no previous file with comments | « client/run_isolated.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698