From cdb70fee333692e9c0d6f28235ad10102a490df9 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio <35803280+lobis@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:36:48 +0100 Subject: [PATCH] test: add test for issue 1054 (newer fsspec failing to parse files with colons in name) (#1055) * add test for issue 1054 * additional test * make sure fsspec fix works * try new test in older fsspec version (need to test windows) * skip test in windows due to colons in name * add explicit object-path split with open * revert use fsspec fork in ci --- src/uproot/version.py | 2 +- tests/test_0692_fsspec_reading.py | 57 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/uproot/version.py b/src/uproot/version.py index 7dc2ff112..05897ca84 100644 --- a/src/uproot/version.py +++ b/src/uproot/version.py @@ -12,7 +12,7 @@ import re -__version__ = "5.2.0rc3" +__version__ = "5.2.0rc4" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__)) diff --git a/tests/test_0692_fsspec_reading.py b/tests/test_0692_fsspec_reading.py index d2851c0d1..18dbaab1f 100644 --- a/tests/test_0692_fsspec_reading.py +++ b/tests/test_0692_fsspec_reading.py @@ -15,6 +15,8 @@ import os import sys +is_windows = sys.platform.startswith("win") + @pytest.mark.parametrize( "urlpath, source_class", @@ -166,6 +168,61 @@ def test_open_fsspec_xrootd(handler): assert (data == 194778).all() +@pytest.mark.parametrize( + "handler", + [ + uproot.source.file.MemmapSource, + uproot.source.file.MultithreadedFileSource, + uproot.source.fsspec.FSSpecSource, + None, + ], +) +@pytest.mark.skipif( + is_windows, reason="Windows does not support colons (':') in filenames" +) +def test_issue_1054_filename_colons(handler): + root_filename = "uproot-issue121.root" + local_path = str(skhep_testdata.data_path(root_filename)) + local_path_new = local_path[: -len(root_filename)] + "file:with:colons.root" + os.rename(local_path, local_path_new) + with uproot.open(local_path_new, handler=handler) as f: + data = f["Events/MET_pt"].array(library="np") + assert len(data) == 40 + + with uproot.open(local_path_new + ":Events", handler=handler) as tree: + data = tree["MET_pt"].array(library="np") + assert len(data) == 40 + + with uproot.open(local_path_new + ":Events/MET_pt", handler=handler) as branch: + data = branch.array(library="np") + assert len(data) == 40 + + +@pytest.mark.parametrize( + "handler", + [ + uproot.source.file.MemmapSource, + uproot.source.file.MultithreadedFileSource, + uproot.source.fsspec.FSSpecSource, + None, + ], +) +def test_issue_1054_object_path_split(handler): + root_filename = "uproot-issue121.root" + local_path = str(skhep_testdata.data_path(root_filename)) + with uproot.open(local_path, handler=handler) as f: + data = f["Events/MET_pt"].array(library="np") + assert len(data) == 40 + + with uproot.open(local_path + ":Events", handler=handler) as tree: + data = tree["MET_pt"].array(library="np") + assert len(data) == 40 + + with uproot.open(local_path + ":Events/MET_pt", handler=handler) as branch: + data = branch.array(library="np") + assert len(data) == 40 + + def test_fsspec_chunks(server): pytest.importorskip("aiohttp")