@@ -1599,3 +1599,55 @@ async def test_cat_file_non_zonal_fallback(extended_gcsfs):
15991599 mock_super_cat .assert_awaited_once_with (
16001600 "standard_bucket/obj" , start = 10 , end = 20 , concurrency = 2 , custom_arg = "val"
16011601 )
1602+
1603+
1604+ @pytest .mark .asyncio
1605+ async def test_lookup_bucket_type_not_cached_unknown (extended_gcsfs ):
1606+ """Test that BucketType.UNKNOWN is not cached when _cache_unknown_buckets is False."""
1607+ fs = extended_gcsfs
1608+ fs ._cache_unknown_buckets = False
1609+
1610+ # Clear cache just in case
1611+ fs ._storage_layout_cache .clear ()
1612+
1613+ # Mock _get_bucket_type to return UNKNOWN
1614+ with mock .patch .object (
1615+ fs , "_get_bucket_type" , new_callable = mock .AsyncMock
1616+ ) as mock_get_type :
1617+ mock_get_type .return_value = BucketType .UNKNOWN
1618+
1619+ # First lookup
1620+ type1 = await fs ._lookup_bucket_type ("my-bucket" )
1621+ assert type1 == BucketType .UNKNOWN
1622+ assert mock_get_type .call_count == 1
1623+
1624+ # Second lookup should call _get_bucket_type again because it's not cached
1625+ type2 = await fs ._lookup_bucket_type ("my-bucket" )
1626+ assert type2 == BucketType .UNKNOWN
1627+ assert mock_get_type .call_count == 2
1628+
1629+
1630+ @pytest .mark .asyncio
1631+ async def test_lookup_bucket_type_cached_unknown (extended_gcsfs ):
1632+ """Test that BucketType.UNKNOWN is cached when _cache_unknown_buckets is True."""
1633+ fs = extended_gcsfs
1634+ fs ._cache_unknown_buckets = True
1635+
1636+ # Clear cache just in case
1637+ fs ._storage_layout_cache .clear ()
1638+
1639+ # Mock _get_bucket_type to return UNKNOWN
1640+ with mock .patch .object (
1641+ fs , "_get_bucket_type" , new_callable = mock .AsyncMock
1642+ ) as mock_get_type :
1643+ mock_get_type .return_value = BucketType .UNKNOWN
1644+
1645+ # First lookup
1646+ type1 = await fs ._lookup_bucket_type ("my-bucket" )
1647+ assert type1 == BucketType .UNKNOWN
1648+ assert mock_get_type .call_count == 1
1649+
1650+ # Second lookup should NOT call _get_bucket_type again because it's cached
1651+ type2 = await fs ._lookup_bucket_type ("my-bucket" )
1652+ assert type2 == BucketType .UNKNOWN
1653+ assert mock_get_type .call_count == 1
0 commit comments