Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fsspec cache #1075

Merged
merged 9 commits into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/test_0692_fsspec_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,68 @@ def test_fsspec_globbing_s3(handler):
assert len(array) == 8004


@pytest.mark.parametrize(
"protocol_prefix",
[
"",
"simplecache::",
],
)
def test_fsspec_cache_xrootd(protocol_prefix, xrootd_server, tmp_path):
pytest.importorskip("XRootD")
pytest.importorskip("fsspec_xrootd")

remote_path, local_path = xrootd_server
filename = "uproot-issue121.root"
with open(skhep_testdata.data_path(filename), "rb") as f_read:
with open(os.path.join(local_path, filename), "wb") as f_write:
f_write.write(f_read.read())
remote_file_path = os.path.join(remote_path, filename) # starts with "root://"

cache_path = str(tmp_path / "cache")
with uproot.open(
protocol_prefix + remote_file_path,
simplecache={"cache_storage": cache_path},
) as f:
data = f["Events/MET_pt"].array(library="np")
assert len(data) == 40


@pytest.mark.parametrize(
"protocol_prefix", # http scheme is already included in the server fixture
[
"",
"simplecache::",
],
)
def test_fsspec_cache_http(http_server, protocol_prefix):
pytest.importorskip("aiohttp")

url = f"{protocol_prefix}{http_server}/uproot-issue121.root"
print(url)
with uproot.open(
url,
) as f:
data = f["Events/MET_pt"].array(library="np")
assert len(data) == 40


def test_fsspec_cache_http_directory(http_server, tmp_path):
pytest.importorskip("aiohttp")

cache_directory = str(tmp_path / "cache")
url = f"simplecache::{http_server}/uproot-issue121.root"
print(tmp_path)
with uproot.open(
url,
simplecache={"cache_storage": cache_directory},
) as f:
data = f["Events/MET_pt"].array(library="np")
assert len(data) == 40

assert len(os.listdir(cache_directory)) == 1


@pytest.mark.parametrize(
"handler",
[
Expand Down