2525 TEST_VERSIONED_BUCKET ,
2626 TEST_ZONAL_BUCKET ,
2727)
28+ from gcsfs .tests .utils import is_real_gcs
2829
2930files = {
3031 "test/accounts.1.json" : (
7980def _avoid_adc_timeout (monkeypatch ):
8081 """Avoid slow ADC lookups and Metadata Server requests in tests."""
8182 # Do not apply if tests are explicitly running against real GCS
82- if os . environ . get ( "STORAGE_EMULATOR_HOST" ) == "https://storage.googleapis.com" :
83+ if is_real_gcs () :
8384 yield
8485 return
8586
@@ -103,7 +104,7 @@ def stop_docker(container):
103104@pytest .fixture (scope = "session" )
104105def docker_gcs ():
105106 if "STORAGE_EMULATOR_HOST" in os .environ :
106- if os . environ [ "STORAGE_EMULATOR_HOST" ] != "https://storage.googleapis.com" :
107+ if not is_real_gcs () :
107108 params ["token" ] = "anon"
108109 # assume using real API or otherwise have a server already set up
109110 yield os .getenv ("STORAGE_EMULATOR_HOST" )
@@ -140,9 +141,8 @@ def gcs_factory(docker_gcs):
140141 def factory (** kwargs ):
141142 GCSFileSystem .clear_instance_cache ()
142143 fs = fsspec .filesystem ("gcs" , ** params , ** kwargs )
143- # Enable caching of UNKNOWN bucket types if we are on emulator
144- is_emulator = params .get ("endpoint_url" ) != "https://storage.googleapis.com"
145- if is_emulator and isinstance (fs , ExtendedGcsFileSystem ):
144+ # Enable caching of UNKNOWN bucket types if not using real GCS
145+ if not is_real_gcs () and isinstance (fs , ExtendedGcsFileSystem ):
146146 fs ._cache_unknown_buckets = True
147147 return fs
148148
@@ -308,9 +308,6 @@ def final_cleanup(gcs_factory, buckets_to_delete):
308308def gcs_versioned (gcs_factory , buckets_to_delete ):
309309 gcs = gcs_factory ()
310310 gcs .version_aware = True
311- is_real_gcs = (
312- os .environ .get ("STORAGE_EMULATOR_HOST" ) == "https://storage.googleapis.com"
313- )
314311 try : # ensure we're empty.
315312 # The versioned bucket might be created by `is_versioning_enabled`
316313 # in test_core_versioned.py. We must register it for cleanup only if
@@ -324,7 +321,7 @@ def gcs_versioned(gcs_factory, buckets_to_delete):
324321 buckets_to_delete .add (TEST_VERSIONED_BUCKET )
325322 except ImportError :
326323 pass # test_core_versioned is not being run
327- if is_real_gcs :
324+ if is_real_gcs () :
328325 cleanup_versioned_bucket (gcs , TEST_VERSIONED_BUCKET )
329326 else :
330327 # For emulators, we delete and recreate the bucket for a clean state
@@ -339,7 +336,7 @@ def gcs_versioned(gcs_factory, buckets_to_delete):
339336 finally :
340337 # Ensure the bucket is empty after the test.
341338 try :
342- if is_real_gcs :
339+ if is_real_gcs () :
343340 cleanup_versioned_bucket (gcs , TEST_VERSIONED_BUCKET )
344341 except Exception as e :
345342 logging .warning (
@@ -385,13 +382,9 @@ def cleanup_versioned_bucket(gcs, bucket_name, prefix=None):
385382
386383
387384def _create_extended_gcsfs (gcs_factory , buckets_to_delete , populate_bucket , ** kwargs ):
388- is_real_gcs = (
389- os .environ .get ("STORAGE_EMULATOR_HOST" ) == "https://storage.googleapis.com"
390- )
391-
392385 extended_gcsfs = gcs_factory (** kwargs )
393386 # Only create/delete/populate the bucket if we are NOT using the real GCS endpoint.
394- if not is_real_gcs :
387+ if not is_real_gcs () :
395388 if not extended_gcsfs .exists (TEST_ZONAL_BUCKET ):
396389 extended_gcsfs .mkdir (TEST_ZONAL_BUCKET )
397390 buckets_to_delete .add (TEST_ZONAL_BUCKET )
@@ -451,14 +444,14 @@ def gcs_hns(gcs_factory, buckets_to_delete):
451444def zonal_write_mocks ():
452445 """A fixture for mocking Zonal bucket write functionality."""
453446
454- if os . environ . get ( "STORAGE_EMULATOR_HOST" ) == "https://storage.googleapis.com" :
447+ if is_real_gcs () :
455448 yield None
456449 return
457450
458- patch_target_get_bucket_type = (
451+ patch_target_lookup_bucket_type = (
459452 "gcsfs.extended_gcsfs.ExtendedGcsFileSystem._lookup_bucket_type"
460453 )
461- patch_target_sync_get_bucket_type = (
454+ patch_target_sync_lookup_bucket_type = (
462455 "gcsfs.extended_gcsfs.ExtendedGcsFileSystem._sync_lookup_bucket_type"
463456 )
464457 patch_target_init_aaow = "gcsfs.zb_hns_utils.init_aaow"
@@ -490,12 +483,12 @@ async def finalize_side_effect():
490483
491484 with (
492485 mock .patch (
493- patch_target_get_bucket_type ,
486+ patch_target_lookup_bucket_type ,
494487 new_callable = mock .AsyncMock ,
495488 return_value = BucketType .ZONAL_HIERARCHICAL ,
496489 ),
497490 mock .patch (
498- patch_target_sync_get_bucket_type ,
491+ patch_target_sync_lookup_bucket_type ,
499492 return_value = BucketType .ZONAL_HIERARCHICAL ,
500493 ),
501494 mock .patch (patch_target_gcsfs_info , mock_gcsfs_info ),
0 commit comments