@@ -2068,6 +2068,8 @@ def test_download_as_text_w_non_ascii_wo_explicit_encoding_w_charset(self):
2068
2068
2069
2069
@mock .patch ("warnings.warn" )
2070
2070
def test_download_as_string (self , mock_warn ):
2071
+ from google .cloud .storage .blob import _DOWNLOAD_AS_STRING_DEPRECATED
2072
+
2071
2073
MEDIA_LINK = "http://example.com/media/"
2072
2074
2073
2075
client = self ._make_client ()
@@ -2096,14 +2098,14 @@ def test_download_as_string(self, mock_warn):
2096
2098
retry = DEFAULT_RETRY ,
2097
2099
)
2098
2100
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 ,
2104
2103
)
2105
2104
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
+
2107
2109
MEDIA_LINK = "http://example.com/media/"
2108
2110
2109
2111
client = self ._make_client ()
@@ -2132,6 +2134,10 @@ def test_download_as_string_no_retry(self):
2132
2134
retry = None ,
2133
2135
)
2134
2136
2137
+ mock_warn .assert_called_once_with (
2138
+ _DOWNLOAD_AS_STRING_DEPRECATED , PendingDeprecationWarning , stacklevel = 2 ,
2139
+ )
2140
+
2135
2141
def test__get_content_type_explicit (self ):
2136
2142
blob = self ._make_one (u"blob-name" , bucket = None )
2137
2143
@@ -2718,7 +2724,7 @@ def test__initiate_resumable_upload_with_extra_headers(self):
2718
2724
def test__initiate_resumable_upload_with_retry (self ):
2719
2725
self ._initiate_resumable_helper (retry = DEFAULT_RETRY )
2720
2726
2721
- def test__initiate_resumable_upload_with_num_retries (self ):
2727
+ def test__initiate_resumable_upload_w_num_retries (self ):
2722
2728
self ._initiate_resumable_helper (num_retries = 11 )
2723
2729
2724
2730
def test__initiate_resumable_upload_with_retry_conflict (self ):
@@ -2983,7 +2989,7 @@ def test__do_resumable_upload_with_size(self):
2983
2989
def test__do_resumable_upload_with_retry (self ):
2984
2990
self ._do_resumable_helper (retry = DEFAULT_RETRY )
2985
2991
2986
- def test__do_resumable_upload_with_num_retries (self ):
2992
+ def test__do_resumable_upload_w_num_retries (self ):
2987
2993
self ._do_resumable_helper (num_retries = 8 )
2988
2994
2989
2995
def test__do_resumable_upload_with_retry_conflict (self ):
@@ -3129,7 +3135,7 @@ def test__do_upload_uses_resumable_w_custom_timeout(self):
3129
3135
def test__do_upload_with_retry (self ):
3130
3136
self ._do_upload_helper (retry = DEFAULT_RETRY )
3131
3137
3132
- def test__do_upload_with_num_retries (self ):
3138
+ def test__do_upload_w_num_retries (self ):
3133
3139
self ._do_upload_helper (num_retries = 2 )
3134
3140
3135
3141
def test__do_upload_with_conditional_retry_success (self ):
@@ -3199,26 +3205,32 @@ def test_upload_from_file_success(self):
3199
3205
stream = self ._upload_from_file_helper (predefined_acl = "private" )
3200
3206
assert stream .tell () == 2
3201
3207
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 ):
3204
3209
self ._upload_from_file_helper (retry = DEFAULT_RETRY )
3205
3210
3206
3211
@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
3209
3214
3210
3215
self ._upload_from_file_helper (num_retries = 2 )
3216
+
3211
3217
mock_warn .assert_called_once_with (
3212
- blob_module . _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2
3218
+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3213
3219
)
3214
3220
3215
3221
@mock .patch ("warnings.warn" )
3216
3222
def test_upload_from_file_with_retry_conflict (self , mock_warn ):
3223
+ from google .cloud .storage ._helpers import _NUM_RETRIES_MESSAGE
3224
+
3217
3225
# Special case here: in a conflict this method should NOT raise an error
3218
3226
# as that's handled further downstream. It should pass both options
3219
3227
# through.
3220
3228
self ._upload_from_file_helper (retry = DEFAULT_RETRY , num_retries = 2 )
3221
3229
3230
+ mock_warn .assert_called_once_with (
3231
+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3232
+ )
3233
+
3222
3234
def test_upload_from_file_with_rewind (self ):
3223
3235
stream = self ._upload_from_file_helper (rewind = True )
3224
3236
assert stream .tell () == 0
@@ -3342,8 +3354,10 @@ def test_upload_from_filename_with_retry(self):
3342
3354
self .assertEqual (stream .mode , "rb" )
3343
3355
self .assertEqual (stream .name , temp .name )
3344
3356
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 ):
3346
3359
from google .cloud ._testing import _NamedTemporaryFile
3360
+ from google .cloud .storage ._helpers import _NUM_RETRIES_MESSAGE
3347
3361
3348
3362
blob = self ._make_one ("blob-name" , bucket = None )
3349
3363
# Mock low-level upload helper on blob (it is tested elsewhere).
@@ -3375,6 +3389,10 @@ def test_upload_from_filename_with_num_retries(self):
3375
3389
self .assertEqual (stream .mode , "rb" )
3376
3390
self .assertEqual (stream .name , temp .name )
3377
3391
3392
+ mock_warn .assert_called_once_with (
3393
+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3394
+ )
3395
+
3378
3396
def test_upload_from_filename_w_custom_timeout (self ):
3379
3397
from google .cloud ._testing import _NamedTemporaryFile
3380
3398
@@ -3453,10 +3471,17 @@ def test_upload_from_string_w_text_w_retry(self):
3453
3471
data = u"\N{snowman} \N{sailboat} "
3454
3472
self ._upload_from_string_helper (data , retry = DEFAULT_RETRY )
3455
3473
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
+
3457
3478
data = u"\N{snowman} \N{sailboat} "
3458
3479
self ._upload_from_string_helper (data , num_retries = 2 )
3459
3480
3481
+ mock_warn .assert_called_once_with (
3482
+ _NUM_RETRIES_MESSAGE , DeprecationWarning , stacklevel = 2 ,
3483
+ )
3484
+
3460
3485
def _create_resumable_upload_session_helper (
3461
3486
self ,
3462
3487
origin = None ,
@@ -4303,7 +4328,10 @@ def test_compose_w_if_generation_match_list_w_warning(self, mock_warn):
4303
4328
_COMPOSE_IF_GENERATION_LIST_DEPRECATED , DeprecationWarning , stacklevel = 2 ,
4304
4329
)
4305
4330
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
+
4307
4335
source_1_name = "source-1"
4308
4336
source_2_name = "source-2"
4309
4337
destination_name = "destination"
@@ -4324,6 +4352,10 @@ def test_compose_w_if_generation_match_and_if_s_generation_match(self):
4324
4352
4325
4353
client ._post_resource .assert_not_called ()
4326
4354
4355
+ mock_warn .assert_called_with (
4356
+ _COMPOSE_IF_GENERATION_LIST_DEPRECATED , DeprecationWarning , stacklevel = 2 ,
4357
+ )
4358
+
4327
4359
@mock .patch ("warnings.warn" )
4328
4360
def test_compose_w_if_metageneration_match_list_w_warning (self , mock_warn ):
4329
4361
from google .cloud .storage .blob import _COMPOSE_IF_METAGENERATION_LIST_DEPRECATED
0 commit comments