@@ -187,15 +187,18 @@ def release(self, *args, **kwargs):
187187
188188 # Track actual HTTP downloads
189189 import niquests
190+
190191 original_get = niquests .get
191192
192193 def tracked_get (url , * args , ** kwargs ):
193194 with lock_events_lock :
194195 download_attempts .append ((threading .current_thread ().name , url , time .time ()))
195196 return original_get (url , * args , ** kwargs )
196197
197- with patch ("nc_py_api.ex_app.integration_fastapi.SoftFileLock" , TrackedSoftFileLock ), \
198- patch ("nc_py_api.ex_app.integration_fastapi.niquests.get" , side_effect = tracked_get ):
198+ with (
199+ patch ("nc_py_api.ex_app.integration_fastapi.SoftFileLock" , TrackedSoftFileLock ),
200+ patch ("nc_py_api.ex_app.integration_fastapi.niquests.get" , side_effect = tracked_get ),
201+ ):
199202 # Simulate two pods trying to download simultaneously
200203 results = []
201204 errors = []
@@ -251,12 +254,14 @@ def download_in_thread(thread_name):
251254 t2_end = thread_sections [threads [1 ]]["release" ]
252255
253256 # Verify no overlap: either t1 ends before/at t2 start, or t2 ends before/at t1 start
254- assert (t1_end <= t2_start ) or (t2_end <= t1_start ), \
255- f"Critical sections overlap - locks not serialized: { lock_events } "
257+ assert (t1_end <= t2_start ) or (
258+ t2_end <= t1_start
259+ ), f"Critical sections overlap - locks not serialized: { lock_events } "
256260
257261 # Verify file was downloaded only once (second thread should skip due to ETag match)
258- assert len (download_attempts ) == 1 , \
259- f"Expected exactly 1 download, but got { len (download_attempts )} : { download_attempts } "
262+ assert (
263+ len (download_attempts ) == 1
264+ ), f"Expected exactly 1 download, but got { len (download_attempts )} : { download_attempts } "
260265
261266 # Verify file was downloaded successfully
262267 assert Path ("concurrent_test.txt" ).exists ()
@@ -412,15 +417,23 @@ def release(self, *args, **kwargs):
412417 return super ().release (* args , ** kwargs )
413418
414419 # Track actual snapshot_download calls
415- from huggingface_hub import snapshot_download as original_snapshot_download
420+ from huggingface_hub import (
421+ snapshot_download as original_snapshot_download ,
422+ )
416423
417424 def tracked_snapshot_download (* args , ** kwargs ):
418425 with lock_events_lock :
419- download_attempts .append ((threading .current_thread ().name , args [0 ] if args else "unknown" , time .time ()))
426+ download_attempts .append (
427+ (threading .current_thread ().name , args [0 ] if args else "unknown" , time .time ())
428+ )
420429 return original_snapshot_download (* args , ** kwargs )
421430
422- with patch ("nc_py_api.ex_app.integration_fastapi.SoftFileLock" , TrackedSoftFileLock ), \
423- patch ("nc_py_api.ex_app.integration_fastapi.snapshot_download" , side_effect = tracked_snapshot_download ):
431+ with (
432+ patch ("nc_py_api.ex_app.integration_fastapi.SoftFileLock" , TrackedSoftFileLock ),
433+ patch (
434+ "nc_py_api.ex_app.integration_fastapi.snapshot_download" , side_effect = tracked_snapshot_download
435+ ),
436+ ):
424437 # Simulate two pods trying to download simultaneously
425438 results = []
426439 errors = []
@@ -476,14 +489,16 @@ def download_in_thread(thread_name):
476489 t2_end = thread_sections [threads [1 ]]["release" ]
477490
478491 # Verify no overlap: either t1 ends before/at t2 start, or t2 ends before/at t1 start
479- assert (t1_end <= t2_start ) or (t2_end <= t1_start ), \
480- f"Critical sections overlap - locks not serialized: { lock_events } "
492+ assert (t1_end <= t2_start ) or (
493+ t2_end <= t1_start
494+ ), f"Critical sections overlap - locks not serialized: { lock_events } "
481495
482496 # Verify snapshot was downloaded only once (second thread should reuse cached download)
483497 # HuggingFace's snapshot_download has its own caching, so both threads may call it,
484498 # but the lock ensures they don't download concurrently
485- assert len (download_attempts ) <= 2 , \
486- f"Expected at most 2 snapshot_download calls, but got { len (download_attempts )} : { download_attempts } "
499+ assert (
500+ len (download_attempts ) <= 2
501+ ), f"Expected at most 2 snapshot_download calls, but got { len (download_attempts )} : { download_attempts } "
487502
488503 # Verify model was downloaded successfully
489504 assert cache_dir .exists ()
0 commit comments