| OLD | NEW |
| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 self.ret_codes = Queue.Queue() | 126 self.ret_codes = Queue.Queue() |
| 127 self.lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') | 127 self.lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') |
| 128 self.lorem_ipsum_sha1 = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' | 128 self.lorem_ipsum_sha1 = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' |
| 129 self.maxDiff = None | 129 self.maxDiff = None |
| 130 | 130 |
| 131 def cleanUp(self): | 131 def cleanUp(self): |
| 132 shutil.rmtree(self.temp_dir) | 132 shutil.rmtree(self.temp_dir) |
| 133 | 133 |
| 134 def test_enumerate_files_non_recursive(self): | 134 def test_enumerate_files_non_recursive(self): |
| 135 queue_size = download_from_google_storage.enumerate_work_queue( | 135 queue_size = download_from_google_storage.enumerate_work_queue( |
| 136 self.base_path, self.queue, True, False, False, None, False) | 136 self.base_path, self.queue, True, False, False, None, False, False) |
| 137 expected_queue = [ | 137 expected_queue = [ |
| 138 ('e6c4fbd4fe7607f3e6ebf68b2ea4ef694da7b4fe', | 138 ('e6c4fbd4fe7607f3e6ebf68b2ea4ef694da7b4fe', |
| 139 os.path.join(self.base_path, 'rootfolder_text.txt')), | 139 os.path.join(self.base_path, 'rootfolder_text.txt')), |
| 140 ('7871c8e24da15bad8b0be2c36edc9dc77e37727f', | 140 ('7871c8e24da15bad8b0be2c36edc9dc77e37727f', |
| 141 os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt'))] | 141 os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt'))] |
| 142 self.assertEqual(sorted(expected_queue), sorted(self.queue.queue)) | 142 self.assertEqual(sorted(expected_queue), sorted(self.queue.queue)) |
| 143 self.assertEqual(queue_size, 2) | 143 self.assertEqual(queue_size, 2) |
| 144 | 144 |
| 145 def test_enumerate_files_recursive(self): | 145 def test_enumerate_files_recursive(self): |
| 146 queue_size = download_from_google_storage.enumerate_work_queue( | 146 queue_size = download_from_google_storage.enumerate_work_queue( |
| 147 self.base_path, self.queue, True, True, False, None, False) | 147 self.base_path, self.queue, True, True, False, None, False, False) |
| 148 expected_queue = [ | 148 expected_queue = [ |
| 149 ('e6c4fbd4fe7607f3e6ebf68b2ea4ef694da7b4fe', | 149 ('e6c4fbd4fe7607f3e6ebf68b2ea4ef694da7b4fe', |
| 150 os.path.join(self.base_path, 'rootfolder_text.txt')), | 150 os.path.join(self.base_path, 'rootfolder_text.txt')), |
| 151 ('7871c8e24da15bad8b0be2c36edc9dc77e37727f', | 151 ('7871c8e24da15bad8b0be2c36edc9dc77e37727f', |
| 152 os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt')), | 152 os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt')), |
| 153 ('b5415aa0b64006a95c0c409182e628881d6d6463', | 153 ('b5415aa0b64006a95c0c409182e628881d6d6463', |
| 154 os.path.join(self.base_path, 'subfolder', 'subfolder_text.txt'))] | 154 os.path.join(self.base_path, 'subfolder', 'subfolder_text.txt'))] |
| 155 self.assertEqual(sorted(expected_queue), sorted(self.queue.queue)) | 155 self.assertEqual(sorted(expected_queue), sorted(self.queue.queue)) |
| 156 self.assertEqual(queue_size, 3) | 156 self.assertEqual(queue_size, 3) |
| 157 | 157 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 input_filename=sha1_hash, | 235 input_filename=sha1_hash, |
| 236 base_url=self.base_url, | 236 base_url=self.base_url, |
| 237 gsutil=self.gsutil, | 237 gsutil=self.gsutil, |
| 238 num_threads=1, | 238 num_threads=1, |
| 239 directory=False, | 239 directory=False, |
| 240 recursive=False, | 240 recursive=False, |
| 241 force=True, | 241 force=True, |
| 242 output=output_filename, | 242 output=output_filename, |
| 243 ignore_errors=False, | 243 ignore_errors=False, |
| 244 sha1_file=False, | 244 sha1_file=False, |
| 245 verbose=True) | 245 verbose=True, |
| 246 auto_platform=False) |
| 246 expected_calls = [ | 247 expected_calls = [ |
| 247 ('check_call', | 248 ('check_call', |
| 248 ('ls', input_filename)), | 249 ('ls', input_filename)), |
| 249 ('check_call', | 250 ('check_call', |
| 250 ('cp', '-q', input_filename, output_filename)) | 251 ('cp', '-q', input_filename, output_filename)) |
| 251 ] | 252 ] |
| 252 if sys.platform != 'win32': | 253 if sys.platform != 'win32': |
| 253 expected_calls.append( | 254 expected_calls.append( |
| 254 ('check_call', | 255 ('check_call', |
| 255 ('ls', | 256 ('ls', |
| (...skipping 10 matching lines...) Expand all Loading... |
| 266 input_filename=self.base_path, | 267 input_filename=self.base_path, |
| 267 base_url=self.base_url, | 268 base_url=self.base_url, |
| 268 gsutil=self.gsutil, | 269 gsutil=self.gsutil, |
| 269 num_threads=1, | 270 num_threads=1, |
| 270 directory=True, | 271 directory=True, |
| 271 recursive=False, | 272 recursive=False, |
| 272 force=False, | 273 force=False, |
| 273 output=None, | 274 output=None, |
| 274 ignore_errors=False, | 275 ignore_errors=False, |
| 275 sha1_file=False, | 276 sha1_file=False, |
| 276 verbose=True) | 277 verbose=True, |
| 278 auto_platform=False) |
| 277 expected_calls = [ | 279 expected_calls = [ |
| 278 ('check_call', | 280 ('check_call', |
| 279 ('ls', input_filename)), | 281 ('ls', input_filename)), |
| 280 ('check_call', | 282 ('check_call', |
| 281 ('cp', '-q', input_filename, output_filename))] | 283 ('cp', '-q', input_filename, output_filename))] |
| 282 if sys.platform != 'win32': | 284 if sys.platform != 'win32': |
| 283 expected_calls.append( | 285 expected_calls.append( |
| 284 ('check_call', | 286 ('check_call', |
| 285 ('ls', | 287 ('ls', |
| 286 '-L', | 288 '-L', |
| 287 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) | 289 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) |
| 288 self.assertEqual(self.gsutil.history, expected_calls) | 290 self.assertEqual(self.gsutil.history, expected_calls) |
| 289 self.assertEqual(code, 0) | 291 self.assertEqual(code, 0) |
| 290 | 292 |
| 291 | 293 |
| 292 if __name__ == '__main__': | 294 if __name__ == '__main__': |
| 293 unittest.main() | 295 unittest.main() |
| OLD | NEW |