Skip to content

Commit 831db8c

Browse files
committed
Fix test_blockcache_workflow
1 parent 4149053 commit 831db8c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fsspec/implementations/tests/test_cached.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def test_idempotent():
213213
assert fs3.storage == fs.storage
214214

215215

216-
def test_blockcache_workflow(ftp_writable, tmp_path):
216+
@pytest.mark.parametrize("force_save_pickle", [True, False])
217+
def test_blockcache_workflow(ftp_writable, tmp_path, force_save_pickle):
217218
host, port, user, pw = ftp_writable
218219
fs = FTPFileSystem(host, port, user, pw)
219220
with fs.open("/out", "wb") as f:
@@ -233,6 +234,7 @@ def test_blockcache_workflow(ftp_writable, tmp_path):
233234

234235
# Open the blockcache and read a little bit of the data
235236
fs = fsspec.filesystem("blockcache", **fs_kwargs)
237+
fs._metadata._force_save_pickle = force_save_pickle
236238
with fs.open("/out", "rb", block_size=5) as f:
237239
assert f.read(5) == b"test\n"
238240

@@ -241,13 +243,18 @@ def test_blockcache_workflow(ftp_writable, tmp_path):
241243
del fs
242244

243245
# Check that cache file only has the first two blocks
244-
with open(tmp_path / "cache", "rb") as f:
245-
cache = pickle.load(f)
246-
assert "/out" in cache
247-
assert cache["/out"]["blocks"] == [0, 1]
246+
if force_save_pickle:
247+
with open(tmp_path / "cache", "rb") as f:
248+
cache = pickle.load(f)
249+
else:
250+
with open(tmp_path / "cache", "r") as f:
251+
cache = json.load(f)
252+
assert "/out" in cache
253+
assert cache["/out"]["blocks"] == [0, 1]
248254

249255
# Reopen the same cache and read some more...
250256
fs = fsspec.filesystem("blockcache", **fs_kwargs)
257+
fs._metadata._force_save_pickle = force_save_pickle
251258
with fs.open("/out", block_size=5) as f:
252259
assert f.read(5) == b"test\n"
253260
f.seek(30)

0 commit comments

Comments
 (0)