Skip to content

Commit d5bc01d

Browse files
authored
test: fsspec cache (#1075)
* test for xrootd cache * add tests for caching with fsspec * working cache directory test * no longer skip xrootd cache test * use xrootd_server fixture * install dev version of fsspec-xrootd * fix bad fixture name * remove ci install of fsspec
1 parent 2661616 commit d5bc01d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/test_0692_fsspec_reading.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,68 @@ def test_fsspec_globbing_s3(handler):
478478
assert len(array) == 8004
479479

480480

481+
@pytest.mark.parametrize(
482+
"protocol_prefix",
483+
[
484+
"",
485+
"simplecache::",
486+
],
487+
)
488+
def test_fsspec_cache_xrootd(protocol_prefix, xrootd_server, tmp_path):
489+
pytest.importorskip("XRootD")
490+
pytest.importorskip("fsspec_xrootd")
491+
492+
remote_path, local_path = xrootd_server
493+
filename = "uproot-issue121.root"
494+
with open(skhep_testdata.data_path(filename), "rb") as f_read:
495+
with open(os.path.join(local_path, filename), "wb") as f_write:
496+
f_write.write(f_read.read())
497+
remote_file_path = os.path.join(remote_path, filename) # starts with "root://"
498+
499+
cache_path = str(tmp_path / "cache")
500+
with uproot.open(
501+
protocol_prefix + remote_file_path,
502+
simplecache={"cache_storage": cache_path},
503+
) as f:
504+
data = f["Events/MET_pt"].array(library="np")
505+
assert len(data) == 40
506+
507+
508+
@pytest.mark.parametrize(
509+
"protocol_prefix", # http scheme is already included in the server fixture
510+
[
511+
"",
512+
"simplecache::",
513+
],
514+
)
515+
def test_fsspec_cache_http(http_server, protocol_prefix):
516+
pytest.importorskip("aiohttp")
517+
518+
url = f"{protocol_prefix}{http_server}/uproot-issue121.root"
519+
print(url)
520+
with uproot.open(
521+
url,
522+
) as f:
523+
data = f["Events/MET_pt"].array(library="np")
524+
assert len(data) == 40
525+
526+
527+
def test_fsspec_cache_http_directory(http_server, tmp_path):
528+
pytest.importorskip("aiohttp")
529+
530+
cache_directory = str(tmp_path / "cache")
531+
url = f"simplecache::{http_server}/uproot-issue121.root"
532+
print(tmp_path)
533+
with uproot.open(
534+
url,
535+
simplecache={"cache_storage": cache_directory},
536+
) as f:
537+
data = f["Events/MET_pt"].array(library="np")
538+
assert len(data) == 40
539+
540+
assert len(os.listdir(cache_directory)) == 1
541+
542+
481543
@pytest.mark.parametrize(
482544
"handler",
483545
[

0 commit comments

Comments
 (0)