| OLD | NEW |
| 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 contextlib |
| 10 import functools | 11 import functools |
| 11 import json | 12 import json |
| 12 import logging | 13 import logging |
| 13 import os | 14 import os |
| 14 import sys | 15 import sys |
| 15 import tempfile | 16 import tempfile |
| 16 import unittest | 17 import unittest |
| 17 | 18 |
| 18 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath( | 19 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath( |
| 19 __file__.decode(sys.getfilesystemencoding())))) | 20 __file__.decode(sys.getfilesystemencoding())))) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 40 | 41 |
| 41 def write_content(filepath, content): | 42 def write_content(filepath, content): |
| 42 with open(filepath, 'wb') as f: | 43 with open(filepath, 'wb') as f: |
| 43 f.write(content) | 44 f.write(content) |
| 44 | 45 |
| 45 | 46 |
| 46 def json_dumps(data): | 47 def json_dumps(data): |
| 47 return json.dumps(data, sort_keys=True, separators=(',', ':')) | 48 return json.dumps(data, sort_keys=True, separators=(',', ':')) |
| 48 | 49 |
| 49 | 50 |
| 51 @contextlib.contextmanager |
| 52 def init_named_caches_stub(_run_dir): |
| 53 yield |
| 54 |
| 55 |
| 50 class StorageFake(object): | 56 class StorageFake(object): |
| 51 def __init__(self, files): | 57 def __init__(self, files): |
| 52 self._files = files.copy() | 58 self._files = files.copy() |
| 53 self.namespace = 'default-gzip' | 59 self.namespace = 'default-gzip' |
| 54 self.location = 'http://localhost:1' | 60 self.location = 'http://localhost:1' |
| 55 | 61 |
| 56 def __enter__(self, *_): | 62 def __enter__(self, *_): |
| 57 return self | 63 return self |
| 58 | 64 |
| 59 def __exit__(self, *_): | 65 def __exit__(self, *_): |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 for i in ('make_tree_read_only', 'make_tree_files_read_only', | 216 for i in ('make_tree_read_only', 'make_tree_files_read_only', |
| 211 'make_tree_deleteable', 'make_tree_writeable'): | 217 'make_tree_deleteable', 'make_tree_writeable'): |
| 212 self.mock(file_path, i, functools.partial(add, i)) | 218 self.mock(file_path, i, functools.partial(add, i)) |
| 213 | 219 |
| 214 ret = run_isolated.run_tha_test( | 220 ret = run_isolated.run_tha_test( |
| 215 command, | 221 command, |
| 216 isolated_hash, | 222 isolated_hash, |
| 217 StorageFake(files), | 223 StorageFake(files), |
| 218 isolateserver.MemoryCache(), | 224 isolateserver.MemoryCache(), |
| 219 None, | 225 None, |
| 220 lambda run_dir: None, | 226 init_named_caches_stub, |
| 221 False, | 227 False, |
| 222 None, | 228 None, |
| 223 None, | 229 None, |
| 224 None, | 230 None, |
| 225 None, | 231 None, |
| 226 None, | 232 None, |
| 227 None, | 233 None, |
| 228 run_isolated.noop_install_packages, | 234 run_isolated.noop_install_packages, |
| 229 False) | 235 False) |
| 230 self.assertEqual(0, ret) | 236 self.assertEqual(0, ret) |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 server.add_content('default-store', isolated_data) | 586 server.add_content('default-store', isolated_data) |
| 581 store = isolateserver.get_storage(server.url, 'default-store') | 587 store = isolateserver.get_storage(server.url, 'default-store') |
| 582 | 588 |
| 583 self.mock(sys, 'stdout', StringIO.StringIO()) | 589 self.mock(sys, 'stdout', StringIO.StringIO()) |
| 584 ret = run_isolated.run_tha_test( | 590 ret = run_isolated.run_tha_test( |
| 585 None, | 591 None, |
| 586 isolated_hash, | 592 isolated_hash, |
| 587 store, | 593 store, |
| 588 isolateserver.MemoryCache(), | 594 isolateserver.MemoryCache(), |
| 589 None, | 595 None, |
| 590 lambda run_dir: None, | 596 init_named_caches_stub, |
| 591 False, | 597 False, |
| 592 None, | 598 None, |
| 593 None, | 599 None, |
| 594 None, | 600 None, |
| 595 None, | 601 None, |
| 596 None, | 602 None, |
| 597 None, | 603 None, |
| 598 run_isolated.noop_install_packages, | 604 run_isolated.noop_install_packages, |
| 599 False) | 605 False) |
| 600 self.assertEqual(0, ret) | 606 self.assertEqual(0, ret) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 server.add_content('default-store', isolated_data) | 672 server.add_content('default-store', isolated_data) |
| 667 store = isolateserver.get_storage(server.url, 'default-store') | 673 store = isolateserver.get_storage(server.url, 'default-store') |
| 668 | 674 |
| 669 self.mock(sys, 'stdout', StringIO.StringIO()) | 675 self.mock(sys, 'stdout', StringIO.StringIO()) |
| 670 ret = run_isolated.run_tha_test( | 676 ret = run_isolated.run_tha_test( |
| 671 None, | 677 None, |
| 672 isolated_hash, | 678 isolated_hash, |
| 673 store, | 679 store, |
| 674 isolateserver.MemoryCache(), | 680 isolateserver.MemoryCache(), |
| 675 ['foo', 'foodir/foo2'], | 681 ['foo', 'foodir/foo2'], |
| 676 lambda run_dir: None, | 682 init_named_caches_stub, |
| 677 False, | 683 False, |
| 678 None, | 684 None, |
| 679 None, | 685 None, |
| 680 None, | 686 None, |
| 681 None, | 687 None, |
| 682 None, | 688 None, |
| 683 None, | 689 None, |
| 684 run_isolated.noop_install_packages, | 690 run_isolated.noop_install_packages, |
| 685 False) | 691 False) |
| 686 self.assertEqual(0, ret) | 692 self.assertEqual(0, ret) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 self.assertEqual(expected, actual) | 845 self.assertEqual(expected, actual) |
| 840 | 846 |
| 841 | 847 |
| 842 if __name__ == '__main__': | 848 if __name__ == '__main__': |
| 843 fix_encoding.fix_encoding() | 849 fix_encoding.fix_encoding() |
| 844 if '-v' in sys.argv: | 850 if '-v' in sys.argv: |
| 845 unittest.TestCase.maxDiff = None | 851 unittest.TestCase.maxDiff = None |
| 846 logging.basicConfig( | 852 logging.basicConfig( |
| 847 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 853 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
| 848 unittest.main() | 854 unittest.main() |
| OLD | NEW |