@@ -110,9 +110,10 @@ def test_upload_many_passes_concurrency_options():
110110 ]
111111 MAX_WORKERS = 7
112112 DEADLINE = 10
113- with mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch , mock .patch (
114- "concurrent.futures.wait"
115- ) as wait_patch :
113+ with (
114+ mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch ,
115+ mock .patch ("concurrent.futures.wait" ) as wait_patch ,
116+ ):
116117 transfer_manager .upload_many (
117118 FILE_BLOB_PAIRS ,
118119 deadline = DEADLINE ,
@@ -130,9 +131,10 @@ def test_threads_deprecation_with_upload():
130131 ]
131132 MAX_WORKERS = 7
132133 DEADLINE = 10
133- with mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch , mock .patch (
134- "concurrent.futures.wait"
135- ) as wait_patch :
134+ with (
135+ mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch ,
136+ mock .patch ("concurrent.futures.wait" ) as wait_patch ,
137+ ):
136138 with pytest .warns ():
137139 transfer_manager .upload_many (
138140 FILE_BLOB_PAIRS , deadline = DEADLINE , threads = MAX_WORKERS
@@ -321,9 +323,10 @@ def test_download_many_passes_concurrency_options():
321323 ]
322324 MAX_WORKERS = 7
323325 DEADLINE = 10
324- with mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch , mock .patch (
325- "concurrent.futures.wait"
326- ) as wait_patch :
326+ with (
327+ mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch ,
328+ mock .patch ("concurrent.futures.wait" ) as wait_patch ,
329+ ):
327330 transfer_manager .download_many (
328331 BLOB_FILE_PAIRS ,
329332 deadline = DEADLINE ,
@@ -965,10 +968,10 @@ def test_download_chunks_concurrently_passes_concurrency_options():
965968 MULTIPLE = 4
966969 blob_mock .size = CHUNK_SIZE * MULTIPLE
967970
968- with mock . patch ( "concurrent.futures.ThreadPoolExecutor" ) as pool_patch , mock . patch (
969- "concurrent.futures.wait"
970- ) as wait_patch , mock .patch (
971- "google.cloud.storage.transfer_manager.open" , mock .mock_open ()
971+ with (
972+ mock . patch ( "concurrent.futures.ThreadPoolExecutor" ) as pool_patch ,
973+ mock .patch ("concurrent.futures.wait" ) as wait_patch ,
974+ mock . patch ( "google.cloud.storage.transfer_manager.open" , mock .mock_open ()),
972975 ):
973976 transfer_manager .download_chunks_concurrently (
974977 blob_mock ,
@@ -1002,11 +1005,15 @@ def test_upload_chunks_concurrently():
10021005 ETAG = "efgh"
10031006 part_mock .etag = ETAG
10041007
1005- with mock .patch ("os.path.getsize" , return_value = SIZE ), mock .patch (
1006- "google.cloud.storage.transfer_manager.XMLMPUContainer" ,
1007- return_value = container_mock ,
1008- ), mock .patch (
1009- "google.cloud.storage.transfer_manager.XMLMPUPart" , return_value = part_mock
1008+ with (
1009+ mock .patch ("os.path.getsize" , return_value = SIZE ),
1010+ mock .patch (
1011+ "google.cloud.storage.transfer_manager.XMLMPUContainer" ,
1012+ return_value = container_mock ,
1013+ ),
1014+ mock .patch (
1015+ "google.cloud.storage.transfer_manager.XMLMPUPart" , return_value = part_mock
1016+ ),
10101017 ):
10111018 transfer_manager .upload_chunks_concurrently (
10121019 FILENAME ,
@@ -1045,10 +1052,15 @@ def test_upload_chunks_concurrently_quotes_urls():
10451052 part_mock .etag = ETAG
10461053 container_cls_mock = mock .Mock (return_value = container_mock )
10471054
1048- with mock .patch ("os.path.getsize" , return_value = SIZE ), mock .patch (
1049- "google.cloud.storage.transfer_manager.XMLMPUContainer" , new = container_cls_mock
1050- ), mock .patch (
1051- "google.cloud.storage.transfer_manager.XMLMPUPart" , return_value = part_mock
1055+ with (
1056+ mock .patch ("os.path.getsize" , return_value = SIZE ),
1057+ mock .patch (
1058+ "google.cloud.storage.transfer_manager.XMLMPUContainer" ,
1059+ new = container_cls_mock ,
1060+ ),
1061+ mock .patch (
1062+ "google.cloud.storage.transfer_manager.XMLMPUPart" , return_value = part_mock
1063+ ),
10521064 ):
10531065 transfer_manager .upload_chunks_concurrently (
10541066 FILENAME ,
@@ -1089,12 +1101,15 @@ def test_upload_chunks_concurrently_passes_concurrency_options():
10891101 MAX_WORKERS = 7
10901102 DEADLINE = 10
10911103
1092- with mock .patch ("os.path.getsize" , return_value = SIZE ), mock .patch (
1093- "google.cloud.storage.transfer_manager.XMLMPUContainer" ,
1094- return_value = container_mock ,
1095- ), mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch , mock .patch (
1096- "concurrent.futures.wait"
1097- ) as wait_patch :
1104+ with (
1105+ mock .patch ("os.path.getsize" , return_value = SIZE ),
1106+ mock .patch (
1107+ "google.cloud.storage.transfer_manager.XMLMPUContainer" ,
1108+ return_value = container_mock ,
1109+ ),
1110+ mock .patch ("concurrent.futures.ThreadPoolExecutor" ) as pool_patch ,
1111+ mock .patch ("concurrent.futures.wait" ) as wait_patch ,
1112+ ):
10981113 try :
10991114 transfer_manager .upload_chunks_concurrently (
11001115 FILENAME ,
@@ -1170,13 +1185,19 @@ def test_upload_chunks_concurrently_with_metadata_and_encryption():
11701185
11711186 invocation_id = "b9f8cbb0-6456-420c-819d-3f4ee3c0c455"
11721187
1173- with mock .patch ("os.path.getsize" , return_value = SIZE ), mock .patch (
1174- "google.cloud.storage.transfer_manager.XMLMPUContainer" , new = container_cls_mock
1175- ), mock .patch (
1176- "google.cloud.storage.transfer_manager.XMLMPUPart" , return_value = part_mock
1177- ), mock .patch (
1178- "google.cloud.storage._helpers._get_invocation_id" ,
1179- return_value = "gccl-invocation-id/" + invocation_id ,
1188+ with (
1189+ mock .patch ("os.path.getsize" , return_value = SIZE ),
1190+ mock .patch (
1191+ "google.cloud.storage.transfer_manager.XMLMPUContainer" ,
1192+ new = container_cls_mock ,
1193+ ),
1194+ mock .patch (
1195+ "google.cloud.storage.transfer_manager.XMLMPUPart" , return_value = part_mock
1196+ ),
1197+ mock .patch (
1198+ "google.cloud.storage._helpers._get_invocation_id" ,
1199+ return_value = "gccl-invocation-id/" + invocation_id ,
1200+ ),
11801201 ):
11811202 transfer_manager .upload_chunks_concurrently (
11821203 FILENAME ,
@@ -1280,10 +1301,13 @@ def test_download_chunks_concurrently_with_processes():
12801301 )
12811302 FILENAME = "file_a.txt"
12821303
1283- with mock .patch (
1284- "google.cloud.storage.transfer_manager._download_and_write_chunk_in_place" ,
1285- new = _validate_blob_token_in_subprocess_for_chunk ,
1286- ), mock .patch ("google.cloud.storage.transfer_manager.open" , mock .mock_open ()):
1304+ with (
1305+ mock .patch (
1306+ "google.cloud.storage.transfer_manager._download_and_write_chunk_in_place" ,
1307+ new = _validate_blob_token_in_subprocess_for_chunk ,
1308+ ),
1309+ mock .patch ("google.cloud.storage.transfer_manager.open" , mock .mock_open ()),
1310+ ):
12871311 result = transfer_manager .download_chunks_concurrently (
12881312 blob ,
12891313 FILENAME ,
@@ -1298,9 +1322,12 @@ def test_download_chunks_concurrently_with_processes():
12981322def test__LazyClient ():
12991323 fake_cache = {}
13001324 MOCK_ID = 9999
1301- with mock .patch (
1302- "google.cloud.storage.transfer_manager._cached_clients" , new = fake_cache
1303- ), mock .patch ("google.cloud.storage.transfer_manager.Client" ):
1325+ with (
1326+ mock .patch (
1327+ "google.cloud.storage.transfer_manager._cached_clients" , new = fake_cache
1328+ ),
1329+ mock .patch ("google.cloud.storage.transfer_manager.Client" ),
1330+ ):
13041331 lazyclient = transfer_manager ._LazyClient (MOCK_ID )
13051332 lazyclient_cached = transfer_manager ._LazyClient (MOCK_ID )
13061333 assert lazyclient is lazyclient_cached
@@ -1370,9 +1397,12 @@ def test__reduce_client():
13701397 }
13711398 client ._extra_headers = custom_headers
13721399
1373- with mock .patch (
1374- "google.cloud.storage.transfer_manager._cached_clients" , new = fake_cache
1375- ), mock .patch ("google.cloud.storage.transfer_manager.Client" ):
1400+ with (
1401+ mock .patch (
1402+ "google.cloud.storage.transfer_manager._cached_clients" , new = fake_cache
1403+ ),
1404+ mock .patch ("google.cloud.storage.transfer_manager.Client" ),
1405+ ):
13761406 replicated_client , kwargs = transfer_manager ._reduce_client (client )
13771407 assert replicated_client is not None
13781408 assert custom_headers in kwargs
0 commit comments