@@ -2068,6 +2068,8 @@ def test_download_as_text_w_non_ascii_wo_explicit_encoding_w_charset(self):
20682068
20692069 @mock .patch ("warnings.warn" )
20702070 def test_download_as_string (self , mock_warn ):
2071+ from google .cloud .storage .blob import _DOWNLOAD_AS_STRING_DEPRECATED
2072+
20712073 MEDIA_LINK = "http://example.com/media/"
20722074
20732075 client = self ._make_client ()
@@ -2096,14 +2098,14 @@ def test_download_as_string(self, mock_warn):
20962098 retry = DEFAULT_RETRY ,
20972099 )
20982100
2099- mock_warn .assert_called_with (
2100- "Blob.download_as_string() is deprecated and will be removed in future."
2101- "Use Blob.download_as_bytes() instead." ,
2102- PendingDeprecationWarning ,
2103- stacklevel = 1 ,
2101+ mock_warn .assert_called_once_with (
2102+ _DOWNLOAD_AS_STRING_DEPRECATED , PendingDeprecationWarning , stacklevel = 2 ,
21042103 )
21052104
2106- def test_download_as_string_no_retry (self ):
2105+ @mock .patch ("warnings.warn" )
2106+ def test_download_as_string_no_retry (self , mock_warn ):
2107+ from google .cloud .storage .blob import _DOWNLOAD_AS_STRING_DEPRECATED
2108+
21072109 MEDIA_LINK = "http://example.com/media/"
21082110
21092111 client = self ._make_client ()
@@ -2132,6 +2134,10 @@ def test_download_as_string_no_retry(self):
21322134 retry = None ,
21332135 )
21342136
2137+ mock_warn .assert_called_once_with (
2138+ _DOWNLOAD_AS_STRING_DEPRECATED , PendingDeprecationWarning , stacklevel = 2 ,
2139+ )
2140+
21352141 def test__get_content_type_explicit (self ):
21362142 blob = self ._make_one (u"blob-name" , bucket = None )
21372143
@@ -2718,7 +2724,7 @@ def test__initiate_resumable_upload_with_extra_headers(self):
27182724 def test__initiate_resumable_upload_with_retry (self ):
27192725 self ._initiate_resumable_helper (retry = DEFAULT_RETRY )
27202726
2721- def test__initiate_resumable_upload_with_num_retries (self ):
2727+ def test__initiate_resumable_upload_w_num_retries (self ):
27222728 self ._initiate_resumable_helper (num_retries = 11 )
27232729
27242730 def test__initiate_resumable_upload_with_retry_conflict (self ):
@@ -2983,7 +2989,7 @@ def test__do_resumable_upload_with_size(self):
29832989 def test__do_resumable_upload_with_retry (self ):
29842990 self ._do_resumable_helper (retry = DEFAULT_RETRY )
29852991
2986- def test__do_resumable_upload_with_num_retries (self ):
2992+ def test__do_resumable_upload_w_num_retries (self ):
29872993 self ._do_resumable_helper (num_retries = 8 )
29882994
29892995 def test__do_resumable_upload_with_retry_conflict (self ):
@@ -3129,7 +3135,7 @@ def test__do_upload_uses_resumable_w_custom_timeout(self):
31293135 def test__do_upload_with_retry (self ):
31303136 self ._do_upload_helper (retry = DEFAULT_RETRY )
31313137
3132- def test__do_upload_with_num_retries (self ):
3138+ def test__do_upload_w_num_retries (self ):
31333139 self ._do_upload_helper (num_retries = 2 )
31343140
31353141 def test__do_upload_with_conditional_retry_success (self ):
@@ -3199,26 +3205,32 @@ def test_upload_from_file_success(self):
31993205 stream = self ._upload_from_file_helper (predefined_acl = "private" )
32003206 assert stream .tell () == 2
32013207
3202- @mock .patch ("warnings.warn" )
3203- def test_upload_from_file_with_retries (self , mock_warn ):
3208+ def test_upload_from_file_with_retry (self ):
32043209 self ._upload_from_file_helper (retry = DEFAULT_RETRY )
32053210
32063211 @mock .patch ("warnings.warn" )
3207- def test_upload_from_file_with_num_retries (self , mock_warn ):
3208- from google .cloud .storage import blob as blob_module
3212+ def test_upload_from_file_w_num_retries (self , mock_warn ):
3213+ from google .cloud .storage . _helpers import _NUM_RETRIES_MESSAGE
32093214
32103215 self ._upload_from_file_helper (num_retries = 2 )
3216+
32113217 mock_warn .assert_called_once_with (
3212- blob_module . _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2
3218+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
32133219 )
32143220
32153221 @mock .patch ("warnings.warn" )
32163222 def test_upload_from_file_with_retry_conflict (self , mock_warn ):
3223+ from google .cloud .storage ._helpers import _NUM_RETRIES_MESSAGE
3224+
32173225 # Special case here: in a conflict this method should NOT raise an error
32183226 # as that's handled further downstream. It should pass both options
32193227 # through.
32203228 self ._upload_from_file_helper (retry = DEFAULT_RETRY , num_retries = 2 )
32213229
3230+ mock_warn .assert_called_once_with (
3231+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3232+ )
3233+
32223234 def test_upload_from_file_with_rewind (self ):
32233235 stream = self ._upload_from_file_helper (rewind = True )
32243236 assert stream .tell () == 0
@@ -3342,8 +3354,10 @@ def test_upload_from_filename_with_retry(self):
33423354 self .assertEqual (stream .mode , "rb" )
33433355 self .assertEqual (stream .name , temp .name )
33443356
3345- def test_upload_from_filename_with_num_retries (self ):
3357+ @mock .patch ("warnings.warn" )
3358+ def test_upload_from_filename_w_num_retries (self , mock_warn ):
33463359 from google .cloud ._testing import _NamedTemporaryFile
3360+ from google .cloud .storage ._helpers import _NUM_RETRIES_MESSAGE
33473361
33483362 blob = self ._make_one ("blob-name" , bucket = None )
33493363 # Mock low-level upload helper on blob (it is tested elsewhere).
@@ -3375,6 +3389,10 @@ def test_upload_from_filename_with_num_retries(self):
33753389 self .assertEqual (stream .mode , "rb" )
33763390 self .assertEqual (stream .name , temp .name )
33773391
3392+ mock_warn .assert_called_once_with (
3393+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3394+ )
3395+
33783396 def test_upload_from_filename_w_custom_timeout (self ):
33793397 from google .cloud ._testing import _NamedTemporaryFile
33803398
@@ -3453,10 +3471,17 @@ def test_upload_from_string_w_text_w_retry(self):
34533471 data = u"\N{snowman} \N{sailboat} "
34543472 self ._upload_from_string_helper (data , retry = DEFAULT_RETRY )
34553473
3456- def test_upload_from_string_w_text_w_num_retries (self ):
3474+ @mock .patch ("warnings.warn" )
3475+ def test_upload_from_string_with_num_retries (self , mock_warn ):
3476+ from google .cloud .storage ._helpers import _NUM_RETRIES_MESSAGE
3477+
34573478 data = u"\N{snowman} \N{sailboat} "
34583479 self ._upload_from_string_helper (data , num_retries = 2 )
34593480
3481+ mock_warn .assert_called_once_with (
3482+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3483+ )
3484+
34603485 def _create_resumable_upload_session_helper (
34613486 self ,
34623487 origin = None ,
@@ -4303,7 +4328,10 @@ def test_compose_w_if_generation_match_list_w_warning(self, mock_warn):
43034328 _COMPOSE_IF_GENERATION_LIST_DEPRECATED , DeprecationWarning , stacklevel = 2 ,
43044329 )
43054330
4306- def test_compose_w_if_generation_match_and_if_s_generation_match (self ):
4331+ @mock .patch ("warnings.warn" )
4332+ def test_compose_w_if_generation_match_and_if_s_generation_match (self , mock_warn ):
4333+ from google .cloud .storage .blob import _COMPOSE_IF_GENERATION_LIST_DEPRECATED
4334+
43074335 source_1_name = "source-1"
43084336 source_2_name = "source-2"
43094337 destination_name = "destination"
@@ -4324,6 +4352,10 @@ def test_compose_w_if_generation_match_and_if_s_generation_match(self):
43244352
43254353 client ._post_resource .assert_not_called ()
43264354
4355+ mock_warn .assert_called_with (
4356+ _COMPOSE_IF_GENERATION_LIST_DEPRECATED , DeprecationWarning , stacklevel = 2 ,
4357+ )
4358+
43274359 @mock .patch ("warnings.warn" )
43284360 def test_compose_w_if_metageneration_match_list_w_warning (self , mock_warn ):
43294361 from google .cloud .storage .blob import _COMPOSE_IF_METAGENERATION_LIST_DEPRECATED
0 commit comments