Skip to content

Commit

Permalink
HTTPFileSystem (cached): Improve tests to verify instance reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 24, 2021
1 parent b1f4cad commit ca0a61e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions fsspec/implementations/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ def test_list_cache_with_expiry_time_purged(server):
assert len(cached_items) == 1


def test_list_cache_reuse(server):
h = fsspec.filesystem("http", use_listings_cache=True, listings_expiry_time=5)

# First, the directory cache is not initialized.
assert not h.dircache

# By querying the filesystem with "use_listings_cache=True",
# the cache will automatically get populated.
out = h.glob(server + "/index/*")
assert out == [server + "/index/realfile"]

# Verify cache content.
assert len(h.dircache) == 1

# Verify another instance without caching enabled does not have cache content.
h = fsspec.filesystem("http")
assert not h.dircache

# Verify that yet another new instance, with caching enabled,
# will see the same cache content again.
h = fsspec.filesystem("http", use_listings_cache=True, listings_expiry_time=5)
assert len(h.dircache) == 1

# However, yet another instance with a different expiry time will also not have
# any valid cache content.
h = fsspec.filesystem("http", use_listings_cache=True, listings_expiry_time=666)
assert len(h.dircache) == 0


def test_list_cache_with_max_paths(server):
h = fsspec.filesystem("http", use_listings_cache=True, max_paths=5)
out = h.glob(server + "/index/*")
Expand Down

0 comments on commit ca0a61e

Please sign in to comment.