Skip to content

Commit cb66bf3

Browse files
committed
add tests
1 parent 94b5784 commit cb66bf3

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

gcsfs/tests/test_extended_gcsfs.py

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

0 commit comments

Comments
 (0)