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