@@ -181,8 +181,7 @@ def _get_target_class():
181181 return _DatastoreAPIOverGRPC
182182
183183 def _make_one (self , stub , connection = None , secure = True , mock_args = None ):
184- from google .cloud ._testing import _Monkey
185- from google .cloud .datastore import _http as MUT
184+ import mock
186185
187186 if connection is None :
188187 connection = _Connection (None )
@@ -197,10 +196,15 @@ def mock_make_stub(*args):
197196 return stub
198197
199198 if secure :
200- to_monkey = {'make_secure_stub' : mock_make_stub }
199+ patch = mock .patch (
200+ 'google.cloud.datastore._http.make_secure_stub' ,
201+ new = mock_make_stub )
201202 else :
202- to_monkey = {'make_insecure_stub' : mock_make_stub }
203- with _Monkey (MUT , ** to_monkey ):
203+ patch = mock .patch (
204+ 'google.cloud.datastore._http.make_insecure_stub' ,
205+ new = mock_make_stub )
206+
207+ with patch :
204208 return self ._get_target_class ()(connection , secure )
205209
206210 def test_constructor (self ):
@@ -372,9 +376,10 @@ def _make_query_pb(self, kind):
372376 return pb
373377
374378 def _make_one (self , credentials = None , http = None , use_grpc = False ):
375- from google .cloud ._testing import _Monkey
376- from google .cloud .datastore import _http as MUT
377- with _Monkey (MUT , _USE_GRPC = use_grpc ):
379+ import mock
380+
381+ with mock .patch ('google.cloud.datastore._http._USE_GRPC' ,
382+ new = use_grpc ):
378383 return self ._get_target_class ()(credentials = credentials , http = http )
379384
380385 def _verifyProtobufCall (self , called_with , URI , conn ):
@@ -391,15 +396,14 @@ def test_default_url(self):
391396 self .assertEqual (conn .api_base_url , klass .API_BASE_URL )
392397
393398 def test_custom_url_from_env (self ):
394- import os
395- from google .cloud ._testing import _Monkey
399+ import mock
396400 from google .cloud .connection import API_BASE_URL
397401 from google .cloud .environment_vars import GCD_HOST
398402
399403 HOST = 'CURR_HOST'
400404 fake_environ = {GCD_HOST : HOST }
401405
402- with _Monkey ( os , environ = fake_environ ):
406+ with mock . patch ( 'os.environ' , new = fake_environ ):
403407 conn = self ._make_one ()
404408
405409 self .assertNotEqual (conn .api_base_url , API_BASE_URL )
@@ -410,8 +414,7 @@ def test_ctor_defaults(self):
410414 self .assertIsNone (conn .credentials )
411415
412416 def test_ctor_without_grpc (self ):
413- from google .cloud ._testing import _Monkey
414- from google .cloud .datastore import _http as MUT
417+ import mock
415418
416419 connections = []
417420 return_val = object ()
@@ -420,16 +423,18 @@ def mock_api(connection):
420423 connections .append (connection )
421424 return return_val
422425
423- with _Monkey (MUT , _DatastoreAPIOverHttp = mock_api ):
426+ patch = mock .patch (
427+ 'google.cloud.datastore._http._DatastoreAPIOverHttp' ,
428+ new = mock_api )
429+ with patch :
424430 conn = self ._make_one (use_grpc = False )
425431
426432 self .assertIsNone (conn .credentials )
427433 self .assertIs (conn ._datastore_api , return_val )
428434 self .assertEqual (connections , [conn ])
429435
430436 def test_ctor_with_grpc (self ):
431- from google .cloud ._testing import _Monkey
432- from google .cloud .datastore import _http as MUT
437+ import mock
433438
434439 api_args = []
435440 return_val = object ()
@@ -438,7 +443,10 @@ def mock_api(connection, secure):
438443 api_args .append ((connection , secure ))
439444 return return_val
440445
441- with _Monkey (MUT , _DatastoreAPIOverGRPC = mock_api ):
446+ patch = mock .patch (
447+ 'google.cloud.datastore._http._DatastoreAPIOverGRPC' ,
448+ new = mock_api )
449+ with patch :
442450 conn = self ._make_one (use_grpc = True )
443451
444452 self .assertIsNone (conn .credentials )
@@ -922,9 +930,8 @@ def test_begin_transaction(self):
922930 request .ParseFromString (cw ['body' ])
923931
924932 def test_commit_wo_transaction (self ):
925- from google . cloud . _testing import _Monkey
933+ import mock
926934 from google .cloud .datastore ._generated import datastore_pb2
927- from google .cloud .datastore import _http as MUT
928935 from google .cloud .datastore .helpers import _new_value_pb
929936
930937 PROJECT = 'PROJECT'
@@ -953,7 +960,10 @@ def mock_parse(response):
953960 _parsed .append (response )
954961 return expected_result
955962
956- with _Monkey (MUT , _parse_commit_response = mock_parse ):
963+ patch = mock .patch (
964+ 'google.cloud.datastore._http._parse_commit_response' ,
965+ new = mock_parse )
966+ with patch :
957967 result = conn .commit (PROJECT , req_pb , None )
958968
959969 self .assertIs (result , expected_result )
@@ -968,9 +978,8 @@ def mock_parse(response):
968978 self .assertEqual (_parsed , [rsp_pb ])
969979
970980 def test_commit_w_transaction (self ):
971- from google . cloud . _testing import _Monkey
981+ import mock
972982 from google .cloud .datastore ._generated import datastore_pb2
973- from google .cloud .datastore import _http as MUT
974983 from google .cloud .datastore .helpers import _new_value_pb
975984
976985 PROJECT = 'PROJECT'
@@ -999,7 +1008,10 @@ def mock_parse(response):
9991008 _parsed .append (response )
10001009 return expected_result
10011010
1002- with _Monkey (MUT , _parse_commit_response = mock_parse ):
1011+ patch = mock .patch (
1012+ 'google.cloud.datastore._http._parse_commit_response' ,
1013+ new = mock_parse )
1014+ with patch :
10031015 result = conn .commit (PROJECT , req_pb , b'xact' )
10041016
10051017 self .assertIs (result , expected_result )
0 commit comments