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

Side by Side Diff: depot_tools/tests/download_from_google_storage_unittests.py

Issue 17265012: Honor the --boto flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Created 7 years, 6 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 | « depot_tools/download_from_google_storage.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 (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 # pylint: disable=W0212 5 # pylint: disable=W0212
6 6
7 """Unit tests for download_from_google_storage.py.""" 7 """Unit tests for download_from_google_storage.py."""
8 8
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 10 matching lines...) Expand all
21 import download_from_google_storage 21 import download_from_google_storage
22 22
23 # ../third_party/gsutil/gsutil 23 # ../third_party/gsutil/gsutil
24 GSUTIL_DEFAULT_PATH = os.path.join( 24 GSUTIL_DEFAULT_PATH = os.path.join(
25 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 25 os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
26 'third_party', 'gsutil', 'gsutil') 26 'third_party', 'gsutil', 'gsutil')
27 TEST_DIR = os.path.dirname(os.path.abspath(__file__)) 27 TEST_DIR = os.path.dirname(os.path.abspath(__file__))
28 28
29 29
30 class GsutilMock(object): 30 class GsutilMock(object):
31 def __init__(self, path, boto_path=None, timeout=None): 31 def __init__(self, path, boto_path, timeout=None):
32 self.path = path 32 self.path = path
33 self.timeout = timeout 33 self.timeout = timeout
34 self.boto_path = boto_path 34 self.boto_path = boto_path
35 self.expected = [] 35 self.expected = []
36 self.history = [] 36 self.history = []
37 self.lock = threading.Lock() 37 self.lock = threading.Lock()
38 38
39 def add_expected(self, return_code, out, err): 39 def add_expected(self, return_code, out, err):
40 self.expected.append((return_code, out, err)) 40 self.expected.append((return_code, out, err))
41 41
(...skipping 20 matching lines...) Expand all
62 class GstoolsUnitTests(unittest.TestCase): 62 class GstoolsUnitTests(unittest.TestCase):
63 def setUp(self): 63 def setUp(self):
64 self.temp_dir = tempfile.mkdtemp(prefix='gstools_test') 64 self.temp_dir = tempfile.mkdtemp(prefix='gstools_test')
65 self.base_path = os.path.join(self.temp_dir, 'test_files') 65 self.base_path = os.path.join(self.temp_dir, 'test_files')
66 shutil.copytree(os.path.join(TEST_DIR, 'gstools'), self.base_path) 66 shutil.copytree(os.path.join(TEST_DIR, 'gstools'), self.base_path)
67 67
68 def cleanUp(self): 68 def cleanUp(self):
69 shutil.rmtree(self.temp_dir) 69 shutil.rmtree(self.temp_dir)
70 70
71 def test_gsutil(self): 71 def test_gsutil(self):
72 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH) 72 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH, None)
73 self.assertEqual(gsutil.path, GSUTIL_DEFAULT_PATH) 73 self.assertEqual(gsutil.path, GSUTIL_DEFAULT_PATH)
74 code, _, err = gsutil.check_call() 74 code, _, err = gsutil.check_call()
75 self.assertEqual(code, 0) 75 self.assertEqual(code, 0)
76 self.assertEqual(err, '') 76 self.assertEqual(err, '')
77 77
78 def test_gsutil_version(self): 78 def test_gsutil_version(self):
79 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH) 79 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH, None)
80 _, _, err = gsutil.check_call('version') 80 _, _, err = gsutil.check_call('version')
81 err_lines = err.splitlines() 81 err_lines = err.splitlines()
82 self.assertEqual(err_lines[0], 'gsutil version 3.25') 82 self.assertEqual(err_lines[0], 'gsutil version 3.25')
83 self.assertEqual( 83 self.assertEqual(
84 err_lines[1], 84 err_lines[1],
85 'checksum 010822c61d38d70ac23600bc955fccf5 (OK)') 85 'checksum 010822c61d38d70ac23600bc955fccf5 (OK)')
86 86
87 def test_get_sha1(self): 87 def test_get_sha1(self):
88 lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') 88 lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt')
89 self.assertEqual( 89 self.assertEqual(
(...skipping 25 matching lines...) Expand all
115 self.assertTrue(os.path.exists(lorem_ipsum2_md5)) 115 self.assertTrue(os.path.exists(lorem_ipsum2_md5))
116 self.assertEqual( 116 self.assertEqual(
117 open(lorem_ipsum2_md5, 'rb').read(), 117 open(lorem_ipsum2_md5, 'rb').read(),
118 '4c02d1eb455a0f22c575265d17b84b6d') 118 '4c02d1eb455a0f22c575265d17b84b6d')
119 os.remove(lorem_ipsum2_md5) # Clean up. 119 os.remove(lorem_ipsum2_md5) # Clean up.
120 self.assertFalse(os.path.exists(lorem_ipsum2_md5)) 120 self.assertFalse(os.path.exists(lorem_ipsum2_md5))
121 121
122 122
123 class DownloadTests(unittest.TestCase): 123 class DownloadTests(unittest.TestCase):
124 def setUp(self): 124 def setUp(self):
125 self.gsutil = GsutilMock(GSUTIL_DEFAULT_PATH) 125 self.gsutil = GsutilMock(GSUTIL_DEFAULT_PATH, None)
126 self.temp_dir = tempfile.mkdtemp(prefix='gstools_test') 126 self.temp_dir = tempfile.mkdtemp(prefix='gstools_test')
127 self.checkout_test_files = os.path.join( 127 self.checkout_test_files = os.path.join(
128 TEST_DIR, 'gstools', 'download_test_data') 128 TEST_DIR, 'gstools', 'download_test_data')
129 self.base_path = os.path.join( 129 self.base_path = os.path.join(
130 self.temp_dir, 'download_test_data') 130 self.temp_dir, 'download_test_data')
131 shutil.copytree(self.checkout_test_files, self.base_path) 131 shutil.copytree(self.checkout_test_files, self.base_path)
132 self.base_url = 'gs://sometesturl' 132 self.base_url = 'gs://sometesturl'
133 self.parser = optparse.OptionParser() 133 self.parser = optparse.OptionParser()
134 self.queue = Queue.Queue() 134 self.queue = Queue.Queue()
135 self.ret_codes = Queue.Queue() 135 self.ret_codes = Queue.Queue()
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 expected_calls = [ 272 expected_calls = [
273 ('check_call', 273 ('check_call',
274 ('ls', input_filename)), 274 ('ls', input_filename)),
275 ('check_call', 275 ('check_call',
276 ('cp', '-q', input_filename, output_filename))] 276 ('cp', '-q', input_filename, output_filename))]
277 self.assertEqual(self.gsutil.history, expected_calls) 277 self.assertEqual(self.gsutil.history, expected_calls)
278 self.assertEqual(code, 0) 278 self.assertEqual(code, 0)
279 279
280 280
281 if __name__ == '__main__': 281 if __name__ == '__main__':
282 unittest.main() 282 unittest.main()
OLDNEW
« no previous file with comments | « depot_tools/download_from_google_storage.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698