diff --git a/bigquery/tox.ini b/bigquery/tox.ini index d53f4d83210d..2966a8546dec 100644 --- a/bigquery/tox.ini +++ b/bigquery/tox.ini @@ -7,6 +7,7 @@ localdeps = pip install --quiet --upgrade {toxinidir}/../core deps = pytest + mock covercmd = py.test --quiet \ --cov=google.cloud.bigquery \ diff --git a/bigquery/unit_tests/test_table.py b/bigquery/unit_tests/test_table.py index 45b784e84437..d049107a0769 100644 --- a/bigquery/unit_tests/test_table.py +++ b/bigquery/unit_tests/test_table.py @@ -1640,11 +1640,10 @@ def test_upload_from_file_w_bound_client_multipart(self): def test_upload_from_file_resumable_with_400(self): import csv import datetime + import mock from six.moves.http_client import BAD_REQUEST - from google.cloud.bigquery import table as MUT from google.cloud.exceptions import BadRequest from google.cloud._helpers import UTC - from google.cloud._testing import _Monkey from google.cloud._testing import _NamedTemporaryFile WHEN_TS = 1437767599.006 WHEN = datetime.datetime.utcfromtimestamp(WHEN_TS).replace( @@ -1665,7 +1664,8 @@ class _UploadConfig(object): dataset = _Dataset(client) table = self._make_one(self.TABLE_NAME, dataset=dataset) - with _Monkey(MUT, _UploadConfig=_UploadConfig): + with mock.patch('google.cloud.bigquery.table._UploadConfig', + new=_UploadConfig): with _NamedTemporaryFile() as temp: with open(temp.name, 'w') as file_obj: writer = csv.writer(file_obj) @@ -1680,11 +1680,10 @@ class _UploadConfig(object): # pylint: disable=too-many-statements def test_upload_from_file_w_explicit_client_resumable(self): import json + import mock from six.moves.http_client import OK from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit - from google.cloud._testing import _Monkey - from google.cloud.bigquery import table as MUT UPLOAD_PATH = 'https://example.com/upload/test' initial_response = {'status': OK, 'location': UPLOAD_PATH} @@ -1703,7 +1702,8 @@ class _UploadConfig(object): simple_multipart = True simple_path = u'' # force resumable - with _Monkey(MUT, _UploadConfig=_UploadConfig): + with mock.patch('google.cloud.bigquery.table._UploadConfig', + new=_UploadConfig): orig_requested, PATH, BODY = self._upload_from_file_helper( allow_jagged_rows=False, allow_quoted_newlines=False, diff --git a/datastore/tox.ini b/datastore/tox.ini index 13c0b72d3c98..22efa3321840 100644 --- a/datastore/tox.ini +++ b/datastore/tox.ini @@ -7,6 +7,7 @@ localdeps = pip install --quiet --upgrade {toxinidir}/../core deps = pytest + mock covercmd = py.test --quiet \ --cov=google.cloud.datastore \ diff --git a/datastore/unit_tests/test__http.py b/datastore/unit_tests/test__http.py index e96eed96a032..611bda7e2f3e 100644 --- a/datastore/unit_tests/test__http.py +++ b/datastore/unit_tests/test__http.py @@ -181,8 +181,7 @@ def _get_target_class(): return _DatastoreAPIOverGRPC def _make_one(self, stub, connection=None, secure=True, mock_args=None): - from google.cloud._testing import _Monkey - from google.cloud.datastore import _http as MUT + import mock if connection is None: connection = _Connection(None) @@ -197,10 +196,15 @@ def mock_make_stub(*args): return stub if secure: - to_monkey = {'make_secure_stub': mock_make_stub} + patch = mock.patch( + 'google.cloud.datastore._http.make_secure_stub', + new=mock_make_stub) else: - to_monkey = {'make_insecure_stub': mock_make_stub} - with _Monkey(MUT, **to_monkey): + patch = mock.patch( + 'google.cloud.datastore._http.make_insecure_stub', + new=mock_make_stub) + + with patch: return self._get_target_class()(connection, secure) def test_constructor(self): @@ -372,9 +376,10 @@ def _make_query_pb(self, kind): return pb def _make_one(self, credentials=None, http=None, use_grpc=False): - from google.cloud._testing import _Monkey - from google.cloud.datastore import _http as MUT - with _Monkey(MUT, _USE_GRPC=use_grpc): + import mock + + with mock.patch('google.cloud.datastore._http._USE_GRPC', + new=use_grpc): return self._get_target_class()(credentials=credentials, http=http) def _verifyProtobufCall(self, called_with, URI, conn): @@ -391,15 +396,14 @@ def test_default_url(self): self.assertEqual(conn.api_base_url, klass.API_BASE_URL) def test_custom_url_from_env(self): - import os - from google.cloud._testing import _Monkey + import mock from google.cloud.connection import API_BASE_URL from google.cloud.environment_vars import GCD_HOST HOST = 'CURR_HOST' fake_environ = {GCD_HOST: HOST} - with _Monkey(os, environ=fake_environ): + with mock.patch('os.environ', new=fake_environ): conn = self._make_one() self.assertNotEqual(conn.api_base_url, API_BASE_URL) @@ -410,8 +414,7 @@ def test_ctor_defaults(self): self.assertIsNone(conn.credentials) def test_ctor_without_grpc(self): - from google.cloud._testing import _Monkey - from google.cloud.datastore import _http as MUT + import mock connections = [] return_val = object() @@ -420,7 +423,10 @@ def mock_api(connection): connections.append(connection) return return_val - with _Monkey(MUT, _DatastoreAPIOverHttp=mock_api): + patch = mock.patch( + 'google.cloud.datastore._http._DatastoreAPIOverHttp', + new=mock_api) + with patch: conn = self._make_one(use_grpc=False) self.assertIsNone(conn.credentials) @@ -428,8 +434,7 @@ def mock_api(connection): self.assertEqual(connections, [conn]) def test_ctor_with_grpc(self): - from google.cloud._testing import _Monkey - from google.cloud.datastore import _http as MUT + import mock api_args = [] return_val = object() @@ -438,7 +443,10 @@ def mock_api(connection, secure): api_args.append((connection, secure)) return return_val - with _Monkey(MUT, _DatastoreAPIOverGRPC=mock_api): + patch = mock.patch( + 'google.cloud.datastore._http._DatastoreAPIOverGRPC', + new=mock_api) + with patch: conn = self._make_one(use_grpc=True) self.assertIsNone(conn.credentials) @@ -922,9 +930,8 @@ def test_begin_transaction(self): request.ParseFromString(cw['body']) def test_commit_wo_transaction(self): - from google.cloud._testing import _Monkey + import mock from google.cloud.datastore._generated import datastore_pb2 - from google.cloud.datastore import _http as MUT from google.cloud.datastore.helpers import _new_value_pb PROJECT = 'PROJECT' @@ -953,7 +960,10 @@ def mock_parse(response): _parsed.append(response) return expected_result - with _Monkey(MUT, _parse_commit_response=mock_parse): + patch = mock.patch( + 'google.cloud.datastore._http._parse_commit_response', + new=mock_parse) + with patch: result = conn.commit(PROJECT, req_pb, None) self.assertIs(result, expected_result) @@ -968,9 +978,8 @@ def mock_parse(response): self.assertEqual(_parsed, [rsp_pb]) def test_commit_w_transaction(self): - from google.cloud._testing import _Monkey + import mock from google.cloud.datastore._generated import datastore_pb2 - from google.cloud.datastore import _http as MUT from google.cloud.datastore.helpers import _new_value_pb PROJECT = 'PROJECT' @@ -999,7 +1008,10 @@ def mock_parse(response): _parsed.append(response) return expected_result - with _Monkey(MUT, _parse_commit_response=mock_parse): + patch = mock.patch( + 'google.cloud.datastore._http._parse_commit_response', + new=mock_parse) + with patch: result = conn.commit(PROJECT, req_pb, b'xact') self.assertIs(result, expected_result) diff --git a/datastore/unit_tests/test_client.py b/datastore/unit_tests/test_client.py index 2484d93796bc..61bb56ff96a0 100644 --- a/datastore/unit_tests/test_client.py +++ b/datastore/unit_tests/test_client.py @@ -38,22 +38,20 @@ def _call_fut(self): return _get_gcd_project() def test_no_value(self): - import os - from google.cloud._testing import _Monkey + import mock environ = {} - with _Monkey(os, getenv=environ.get): + with mock.patch('os.getenv', new=environ.get): project = self._call_fut() self.assertIsNone(project) def test_value_set(self): - import os - from google.cloud._testing import _Monkey + import mock from google.cloud.datastore.client import GCD_DATASET MOCK_PROJECT = object() environ = {GCD_DATASET: MOCK_PROJECT} - with _Monkey(os, getenv=environ.get): + with mock.patch('os.getenv', new=environ.get): project = self._call_fut() self.assertEqual(project, MOCK_PROJECT) @@ -67,8 +65,7 @@ def _call_fut(self, project=None): def _determine_default_helper(self, gcd=None, fallback=None, project_called=None): - from google.cloud._testing import _Monkey - from google.cloud.datastore import client + import mock _callers = [] @@ -80,12 +77,11 @@ def fallback_mock(project=None): _callers.append(('fallback_mock', project)) return fallback - patched_methods = { - '_get_gcd_project': gcd_mock, - '_base_default_project': fallback_mock, - } - - with _Monkey(client, **patched_methods): + patch = mock.patch.multiple( + 'google.cloud.datastore.client', + _get_gcd_project=gcd_mock, + _base_default_project=fallback_mock) + with patch: returned_project = self._call_fut(project_called) return returned_project, _callers @@ -141,18 +137,18 @@ def _make_one(self, project=PROJECT, namespace=None, http=http) def test_ctor_w_project_no_environ(self): - from google.cloud._testing import _Monkey - from google.cloud.datastore import client as _MUT + import mock # Some environments (e.g. AppVeyor CI) run in GCE, so # this test would fail artificially. - with _Monkey(_MUT, _base_default_project=lambda project: None): + patch = mock.patch( + 'google.cloud.datastore.client._base_default_project', + new=lambda project: None) + with patch: self.assertRaises(EnvironmentError, self._make_one, None) def test_ctor_w_implicit_inputs(self): - from google.cloud._testing import _Monkey - from google.cloud.datastore import client as _MUT - from google.cloud import client as _base_client + import mock OTHER = 'other' creds = object() @@ -163,10 +159,15 @@ def fallback_mock(project): return project or OTHER klass = self._get_target_class() - with _Monkey(_MUT, - _determine_default_project=fallback_mock): - with _Monkey(_base_client, - get_credentials=lambda: creds): + patch1 = mock.patch( + 'google.cloud.datastore.client._determine_default_project', + new=fallback_mock) + patch2 = mock.patch( + 'google.cloud.client.get_credentials', + new=lambda: creds) + + with patch1: + with patch2: client = klass() self.assertEqual(client.project, OTHER) self.assertIsNone(client.namespace) @@ -495,8 +496,7 @@ def test_get_multi_hit_multiple_keys_different_project(self): client.get_multi([key1, key2]) def test_get_multi_max_loops(self): - from google.cloud._testing import _Monkey - from google.cloud.datastore import client as _MUT + import mock from google.cloud.datastore.key import Key KIND = 'Kind' @@ -513,7 +513,10 @@ def test_get_multi_max_loops(self): key = Key(KIND, ID, project=self.PROJECT) deferred = [] missing = [] - with _Monkey(_MUT, _MAX_LOOPS=-1): + + patch = mock.patch( + 'google.cloud.datastore.client._MAX_LOOPS', new=-1) + with patch: result = client.get_multi([key], missing=missing, deferred=deferred) @@ -702,8 +705,7 @@ def test_key_w_project(self): client.key, KIND, ID, project=self.PROJECT) def test_key_wo_project(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock KIND = 'KIND' ID = 1234 @@ -711,7 +713,9 @@ def test_key_wo_project(self): creds = object() client = self._make_one(credentials=creds) - with _Monkey(MUT, Key=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Key', new=_Dummy) + with patch: key = client.key(KIND, ID) self.assertIsInstance(key, _Dummy) @@ -723,8 +727,7 @@ def test_key_wo_project(self): self.assertEqual(key.kwargs, expected_kwargs) def test_key_w_namespace(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock KIND = 'KIND' ID = 1234 @@ -733,7 +736,9 @@ def test_key_w_namespace(self): creds = object() client = self._make_one(namespace=NAMESPACE, credentials=creds) - with _Monkey(MUT, Key=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Key', new=_Dummy) + with patch: key = client.key(KIND, ID) self.assertIsInstance(key, _Dummy) @@ -744,8 +749,7 @@ def test_key_w_namespace(self): self.assertEqual(key.kwargs, expected_kwargs) def test_key_w_namespace_collision(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock KIND = 'KIND' ID = 1234 @@ -755,7 +759,9 @@ def test_key_w_namespace_collision(self): creds = object() client = self._make_one(namespace=NAMESPACE1, credentials=creds) - with _Monkey(MUT, Key=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Key', new=_Dummy) + with patch: key = client.key(KIND, ID, namespace=NAMESPACE2) self.assertIsInstance(key, _Dummy) @@ -766,13 +772,14 @@ def test_key_w_namespace_collision(self): self.assertEqual(key.kwargs, expected_kwargs) def test_batch(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock creds = object() client = self._make_one(credentials=creds) - with _Monkey(MUT, Batch=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Batch', new=_Dummy) + with patch: batch = client.batch() self.assertIsInstance(batch, _Dummy) @@ -780,13 +787,14 @@ def test_batch(self): self.assertEqual(batch.kwargs, {}) def test_transaction_defaults(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock creds = object() client = self._make_one(credentials=creds) - with _Monkey(MUT, Transaction=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Transaction', new=_Dummy) + with patch: xact = client.transaction() self.assertIsInstance(xact, _Dummy) @@ -812,13 +820,14 @@ def test_query_w_project(self): client.query, kind=KIND, project=self.PROJECT) def test_query_w_defaults(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock creds = object() client = self._make_one(credentials=creds) - with _Monkey(MUT, Query=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Query', new=_Dummy) + with patch: query = client.query() self.assertIsInstance(query, _Dummy) @@ -830,8 +839,7 @@ def test_query_w_defaults(self): self.assertEqual(query.kwargs, expected_kwargs) def test_query_explicit(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock KIND = 'KIND' NAMESPACE = 'NAMESPACE' @@ -844,7 +852,9 @@ def test_query_explicit(self): creds = object() client = self._make_one(credentials=creds) - with _Monkey(MUT, Query=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Query', new=_Dummy) + with patch: query = client.query( kind=KIND, namespace=NAMESPACE, @@ -870,8 +880,7 @@ def test_query_explicit(self): self.assertEqual(query.kwargs, kwargs) def test_query_w_namespace(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock KIND = 'KIND' NAMESPACE = object() @@ -879,7 +888,9 @@ def test_query_w_namespace(self): creds = object() client = self._make_one(namespace=NAMESPACE, credentials=creds) - with _Monkey(MUT, Query=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Query', new=_Dummy) + with patch: query = client.query(kind=KIND) self.assertIsInstance(query, _Dummy) @@ -892,8 +903,7 @@ def test_query_w_namespace(self): self.assertEqual(query.kwargs, expected_kwargs) def test_query_w_namespace_collision(self): - from google.cloud.datastore import client as MUT - from google.cloud._testing import _Monkey + import mock KIND = 'KIND' NAMESPACE1 = object() @@ -902,7 +912,9 @@ def test_query_w_namespace_collision(self): creds = object() client = self._make_one(namespace=NAMESPACE1, credentials=creds) - with _Monkey(MUT, Query=_Dummy): + patch = mock.patch( + 'google.cloud.datastore.client.Query', new=_Dummy) + with patch: query = client.query(kind=KIND, namespace=NAMESPACE2) self.assertIsInstance(query, _Dummy) diff --git a/storage/tox.ini b/storage/tox.ini index 29f5a9c2f146..7c87032c5ed4 100644 --- a/storage/tox.ini +++ b/storage/tox.ini @@ -7,6 +7,7 @@ localdeps = pip install --quiet --upgrade {toxinidir}/../core deps = pytest + mock covercmd = py.test --quiet \ --cov=google.cloud.storage \ diff --git a/storage/unit_tests/test__helpers.py b/storage/unit_tests/test__helpers.py index 039c29c64128..6912addd4d6c 100644 --- a/storage/unit_tests/test__helpers.py +++ b/storage/unit_tests/test__helpers.py @@ -140,8 +140,7 @@ def test_it(self): self.assertEqual(SIGNED_CONTENT, b'kBiQqOnIz21aGlQrIp/r/w==') def test_it_with_stubs(self): - from google.cloud._testing import _Monkey - from google.cloud.storage import _helpers as MUT + import mock class _Buffer(object): @@ -159,7 +158,10 @@ def read(self, block_size): BUFFER = _Buffer([b'', BYTES_TO_SIGN]) MD5 = _MD5(DIGEST_VAL) - with _Monkey(MUT, base64=BASE64, md5=MD5): + patch = mock.patch.multiple( + 'google.cloud.storage._helpers', + base64=BASE64, md5=MD5) + with patch: SIGNED_CONTENT = self._call_fut(BUFFER) self.assertEqual(BUFFER._block_sizes, [8192, 8192]) diff --git a/storage/unit_tests/test_blob.py b/storage/unit_tests/test_blob.py index 281584170896..2813261228a5 100644 --- a/storage/unit_tests/test_blob.py +++ b/storage/unit_tests/test_blob.py @@ -126,8 +126,7 @@ def test_public_url_w_slash_in_name(self): 'https://storage.googleapis.com/name/parent%2Fchild') def _basic_generate_signed_url_helper(self, credentials=None): - from google.cloud._testing import _Monkey - from google.cloud.storage import blob as MUT + import mock BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' @@ -139,7 +138,8 @@ def _basic_generate_signed_url_helper(self, credentials=None): '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() - with _Monkey(MUT, generate_signed_url=SIGNER): + with mock.patch('google.cloud.storage.blob.generate_signed_url', + new=SIGNER): signed_uri = blob.generate_signed_url(EXPIRATION, credentials=credentials) self.assertEqual(signed_uri, URI) @@ -165,8 +165,7 @@ def test_generate_signed_url_w_default_method(self): self._basic_generate_signed_url_helper() def test_generate_signed_url_w_content_type(self): - from google.cloud._testing import _Monkey - from google.cloud.storage import blob as MUT + import mock BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' @@ -179,7 +178,8 @@ def test_generate_signed_url_w_content_type(self): SIGNER = _Signer() CONTENT_TYPE = "text/html" - with _Monkey(MUT, generate_signed_url=SIGNER): + with mock.patch('google.cloud.storage.blob.generate_signed_url', + new=SIGNER): signed_url = blob.generate_signed_url(EXPIRATION, content_type=CONTENT_TYPE) self.assertEqual(signed_url, URI) @@ -203,8 +203,7 @@ def test_generate_signed_url_w_credentials(self): self._basic_generate_signed_url_helper(credentials=credentials) def test_generate_signed_url_w_slash_in_name(self): - from google.cloud._testing import _Monkey - from google.cloud.storage import blob as MUT + import mock BLOB_NAME = 'parent/child' EXPIRATION = '2014-10-16T20:34:37.000Z' @@ -216,7 +215,8 @@ def test_generate_signed_url_w_slash_in_name(self): '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() - with _Monkey(MUT, generate_signed_url=SIGNER): + with mock.patch('google.cloud.storage.blob.generate_signed_url', + new=SIGNER): signed_url = blob.generate_signed_url(EXPIRATION) self.assertEqual(signed_url, URI) @@ -234,8 +234,7 @@ def test_generate_signed_url_w_slash_in_name(self): self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) def test_generate_signed_url_w_method_arg(self): - from google.cloud._testing import _Monkey - from google.cloud.storage import blob as MUT + import mock BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' @@ -247,7 +246,8 @@ def test_generate_signed_url_w_method_arg(self): '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() - with _Monkey(MUT, generate_signed_url=SIGNER): + with mock.patch('google.cloud.storage.blob.generate_signed_url', + new=SIGNER): signed_uri = blob.generate_signed_url(EXPIRATION, method='POST') self.assertEqual(signed_uri, URI) @@ -647,13 +647,12 @@ def test_upload_from_file_simple_both_content_type_sources(self): expected_content_type=EXPECTED_CONTENT_TYPE) def test_upload_from_file_resumable(self): + import mock from six.moves.http_client import OK from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit - from google.cloud._testing import _Monkey from google.cloud._testing import _NamedTemporaryFile from google.cloud.streaming import http_wrapper - from google.cloud.streaming import transfer BLOB_NAME = 'blob-name' UPLOAD_URL = 'http://example.com/upload/name/key' @@ -674,8 +673,12 @@ def test_upload_from_file_resumable(self): blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 5 - # Set the threshhold low enough that we force a resumable uploada. - with _Monkey(transfer, RESUMABLE_UPLOAD_THRESHOLD=5): + # Set the threshhold low enough that we force a resumable upload. + patch = mock.patch( + 'google.cloud.streaming.transfer.RESUMABLE_UPLOAD_THRESHOLD', + new=5) + + with patch: with _NamedTemporaryFile() as temp: with open(temp.name, 'wb') as file_obj: file_obj.write(DATA) @@ -731,12 +734,11 @@ def test_upload_from_file_resumable(self): }) def test_upload_from_file_resumable_w_error(self): + import mock from six.moves.http_client import NOT_FOUND from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit - from google.cloud._testing import _Monkey from google.cloud._testing import _NamedTemporaryFile - from google.cloud.streaming import transfer from google.cloud.streaming.exceptions import HttpError BLOB_NAME = 'blob-name' @@ -751,8 +753,12 @@ def test_upload_from_file_resumable_w_error(self): blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 5 - # Set the threshhold low enough that we force a resumable uploada. - with _Monkey(transfer, RESUMABLE_UPLOAD_THRESHOLD=5): + # Set the threshhold low enough that we force a resumable upload. + patch = mock.patch( + 'google.cloud.streaming.transfer.RESUMABLE_UPLOAD_THRESHOLD', + new=5) + + with patch: with _NamedTemporaryFile() as temp: with open(temp.name, 'wb') as file_obj: file_obj.write(DATA) diff --git a/storage/unit_tests/test_bucket.py b/storage/unit_tests/test_bucket.py index 2ca921d850ec..2c4aa5d87da1 100644 --- a/storage/unit_tests/test_bucket.py +++ b/storage/unit_tests/test_bucket.py @@ -893,9 +893,8 @@ def test_make_public_w_future_reload_default(self): self._make_public_w_future_helper(default_object_acl_loaded=False) def test_make_public_recursive(self): - from google.cloud._testing import _Monkey + import mock from google.cloud.storage.acl import _ACLEntity - from google.cloud.storage import bucket as MUT _saved = [] @@ -934,7 +933,8 @@ def item_to_blob(self, item): bucket.acl.loaded = True bucket.default_object_acl.loaded = True - with _Monkey(MUT, _item_to_blob=item_to_blob): + with mock.patch('google.cloud.storage.bucket._item_to_blob', + new=item_to_blob): bucket.make_public(recursive=True) self.assertEqual(list(bucket.acl), permissive) self.assertEqual(list(bucket.default_object_acl), []) diff --git a/tox.ini b/tox.ini index f60c663d3e67..dc6e229f8a72 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist = [testing] deps = pytest + mock passenv = CI_* CIRCLE*