| Index: gslib/tests/testcase/base.py
|
| ===================================================================
|
| --- gslib/tests/testcase/base.py (revision 33376)
|
| +++ gslib/tests/testcase/base.py (working copy)
|
| @@ -1,3 +1,22 @@
|
| +# -*- coding: utf-8 -*-
|
| +# Copyright 2013 Google Inc. All Rights Reserved.
|
| +#
|
| +# Licensed under the Apache License, Version 2.0 (the "License");
|
| +# you may not use this file except in compliance with the License.
|
| +# You may obtain a copy of the License at
|
| +#
|
| +# http://www.apache.org/licenses/LICENSE-2.0
|
| +#
|
| +# Unless required by applicable law or agreed to in writing, software
|
| +# distributed under the License is distributed on an "AS IS" BASIS,
|
| +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| +# See the License for the specific language governing permissions and
|
| +# limitations under the License.
|
| +"""Base test case class for unit and integration tests."""
|
| +
|
| +from __future__ import absolute_import
|
| +
|
| +from functools import wraps
|
| import os.path
|
| import random
|
| import shutil
|
| @@ -3,14 +22,31 @@
|
| import tempfile
|
|
|
| +import boto
|
| +import gslib.tests.util as util
|
| from gslib.tests.util import unittest
|
|
|
| -
|
| MAX_BUCKET_LENGTH = 63
|
|
|
|
|
| +def NotParallelizable(func):
|
| + @wraps(func)
|
| + def ParallelAnnotatedFunc(*args, **kwargs):
|
| + return func(*args, **kwargs)
|
| + ParallelAnnotatedFunc.is_parallelizable = False
|
| + return ParallelAnnotatedFunc
|
| +
|
| +
|
| class GsUtilTestCase(unittest.TestCase):
|
| """Base test case class for unit and integration tests."""
|
|
|
| def setUp(self):
|
| + if util.RUN_S3_TESTS:
|
| + self.test_api = 'XML'
|
| + self.default_provider = 's3'
|
| + self.provider_custom_meta = 'amz'
|
| + else:
|
| + self.test_api = boto.config.get('GSUtil', 'prefer_api', 'JSON').upper()
|
| + self.default_provider = 'gs'
|
| + self.provider_custom_meta = 'goog'
|
| self.tempdirs = []
|
|
|
| @@ -32,6 +68,7 @@
|
|
|
| Args:
|
| kind: A string indicating what kind of test name this is.
|
| + prefix: Prefix string to be used in the temporary name.
|
|
|
| Returns:
|
| The temporary name.
|
| @@ -69,12 +106,12 @@
|
| Args:
|
| tmpdir: The temporary directory to place the file in. If not specified, a
|
| new temporary directory is created.
|
| + contents: The contents to write to the file. If not specified, a test
|
| + string is constructed and written to the file.
|
| file_name: The name to use for the file. If not specified, a temporary
|
| test file name is constructed. This can also be a tuple, where
|
| ('dir', 'foo') means to create a file named 'foo' inside a
|
| subdirectory named 'dir'.
|
| - contents: The contents to write to the file. If not specified, a test
|
| - string is constructed and written to the file.
|
|
|
| Returns:
|
| The path to the new temporary file.
|
| @@ -87,7 +124,8 @@
|
| fpath = os.path.join(tmpdir, *file_name)
|
| if not os.path.isdir(os.path.dirname(fpath)):
|
| os.makedirs(os.path.dirname(fpath))
|
| - with open(fpath, 'w') as f:
|
| +
|
| + with open(fpath, 'wb') as f:
|
| contents = contents or self.MakeTempName('contents')
|
| f.write(contents)
|
| return fpath
|
|
|