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

Side by Side Diff: third_party/gsutil/gslib/tests/util.py

Issue 1380943003: Roll version of gsutil to 4.15. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase Created 5 years 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
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Copyright 2013 Google Inc. All Rights Reserved. 2 # Copyright 2013 Google Inc. All Rights Reserved.
3 # 3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License. 5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at 6 # You may obtain a copy of the License at
7 # 7 #
8 # http://www.apache.org/licenses/LICENSE-2.0 8 # http://www.apache.org/licenses/LICENSE-2.0
9 # 9 #
10 # Unless required by applicable law or agreed to in writing, software 10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, 11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and 13 # See the License for the specific language governing permissions and
14 # limitations under the License. 14 # limitations under the License.
15 15
16 from __future__ import absolute_import 16 from __future__ import absolute_import
17 17
18 from contextlib import contextmanager 18 from contextlib import contextmanager
19 import functools 19 import functools
20 import os 20 import os
21 import pkgutil 21 import pkgutil
22 import posixpath 22 import posixpath
23 import re 23 import re
24 import tempfile 24 import tempfile
25 import unittest 25 import unittest
26 import urlparse 26 import urlparse
27 27
28 import boto 28 import boto
29 import crcmod
29 import gslib.tests as gslib_tests 30 import gslib.tests as gslib_tests
31 from gslib.util import UsingCrcmodExtension
30 32
31 if not hasattr(unittest.TestCase, 'assertIsNone'): 33 if not hasattr(unittest.TestCase, 'assertIsNone'):
32 # external dependency unittest2 required for Python <= 2.6 34 # external dependency unittest2 required for Python <= 2.6
33 import unittest2 as unittest # pylint: disable=g-import-not-at-top 35 import unittest2 as unittest # pylint: disable=g-import-not-at-top
34 36
35 # Flags for running different types of tests. 37 # Flags for running different types of tests.
36 RUN_INTEGRATION_TESTS = True 38 RUN_INTEGRATION_TESTS = True
37 RUN_UNIT_TESTS = True 39 RUN_UNIT_TESTS = True
38 RUN_S3_TESTS = False 40 RUN_S3_TESTS = False
39 41
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if name == TEST_BOTO_REMOVE_SECTION: 221 if name == TEST_BOTO_REMOVE_SECTION:
220 sections_to_remove.append(section) 222 sections_to_remove.append(section)
221 else: 223 else:
222 boto.config.remove_option(section, name) 224 boto.config.remove_option(section, name)
223 else: 225 else:
224 boto.config.set(section, name, value) 226 boto.config.set(section, name, value)
225 for section in sections_to_remove: 227 for section in sections_to_remove:
226 boto.config.remove_section(section) 228 boto.config.remove_section(section)
227 229
228 230
229 def PerformsFileToObjectUpload(func): 231 def SequentialAndParallelTransfer(func):
230 """Decorator indicating that a test uploads from a local file to an object. 232 """Decorator for tests that perform file to object transfers, or vice versa.
231 233
232 This forces the test to run once normally, and again with special boto 234 This forces the test to run once normally, and again with special boto
233 config settings that will ensure that the test follows the parallel composite 235 config settings that will ensure that the test follows the parallel composite
234 upload code path. 236 upload and/or sliced object download code paths.
235 237
236 Args: 238 Args:
237 func: Function to wrap. 239 func: Function to wrap.
238 240
239 Returns: 241 Returns:
240 Wrapped function. 242 Wrapped function.
241 """ 243 """
242 @functools.wraps(func) 244 @functools.wraps(func)
243 def Wrapper(*args, **kwargs): 245 def Wrapper(*args, **kwargs):
244 # Run the test normally once. 246 # Run the test normally once.
245 func(*args, **kwargs) 247 func(*args, **kwargs)
246 248
247 # Try again, forcing parallel composite uploads. 249 if not RUN_S3_TESTS and UsingCrcmodExtension(crcmod):
248 with SetBotoConfigForTest([ 250 # Try again, forcing parallel upload and sliced download.
249 ('GSUtil', 'parallel_composite_upload_threshold', '1'), 251 with SetBotoConfigForTest([
250 ('GSUtil', 'check_hashes', 'always')]): 252 ('GSUtil', 'parallel_composite_upload_threshold', '1'),
251 func(*args, **kwargs) 253 ('GSUtil', 'sliced_object_download_threshold', '1'),
254 ('GSUtil', 'sliced_object_download_max_components', '3'),
255 ('GSUtil', 'check_hashes', 'always')]):
256 func(*args, **kwargs)
252 257
253 return Wrapper 258 return Wrapper
254 259
255 260
256 @contextmanager 261 @contextmanager
257 def SetBotoConfigForTest(boto_config_list): 262 def SetBotoConfigForTest(boto_config_list):
258 """Sets the input list of boto configs for the duration of a 'with' clause. 263 """Sets the input list of boto configs for the duration of a 'with' clause.
259 264
260 Args: 265 Args:
261 boto_config_list: list of tuples of: 266 boto_config_list: list of tuples of:
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 pass 365 pass
361 366
362 if new_working_directory: 367 if new_working_directory:
363 os.chdir(new_working_directory) 368 os.chdir(new_working_directory)
364 369
365 try: 370 try:
366 yield 371 yield
367 finally: 372 finally:
368 if new_working_directory and prev_working_directory: 373 if new_working_directory and prev_working_directory:
369 os.chdir(prev_working_directory) 374 os.chdir(prev_working_directory)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698