Skip to content

Commit f28ab8b

Browse files
committed
test: improve path object split tests (#1039)
* feat: add fsspec as required dependency (#1021) * fsspec requirements * simplify fsspec import * use loop property * correctly create schemes list * feat: set fsspec as default source (#1023) * feat: add fsspec as required dependency (#1021) * fsspec requirements * simplify fsspec import * use loop property * correctly create schemes list * remove deprecated handlers from docs * simplify source selection * return object source * pickle executor * rename test * test more handlers * option to check writeable file-like object * rename test * explicitly set handler * fix s3 source * rename test * Revert "fix s3 source" This reverts commit e76fdbb. * sesparate PR for s3 fix (#1024) * strip file:// * rename test * rename tests * add aiohttp skip * attempt to parse windows paths * test ci * Revert "test ci" This reverts commit 4c1c8a5. * rename test * remove fsspec from test * remove *_handler options * update defaults * do not override default s3 * do not use fsspec for multiprocessing * rename test * fix not selecting object source * missing import * normalize doc * remove helper * never return None as source * remove unnecessary xrootd source default override since fsspec is default now * rename test * add empty class to pass old pickle test * feat: set `fsspec` (`s3fs`) as default handler for s3 paths (#1032) * feat: add fsspec as required dependency (#1021) * fsspec requirements * simplify fsspec import * use loop property * correctly create schemes list * feat: set fsspec as default source (#1023) * feat: add fsspec as required dependency (#1021) * fsspec requirements * simplify fsspec import * use loop property * correctly create schemes list * remove deprecated handlers from docs * simplify source selection * return object source * pickle executor * rename test * test more handlers * option to check writeable file-like object * rename test * explicitly set handler * fix s3 source * rename test * Revert "fix s3 source" This reverts commit e76fdbb. * sesparate PR for s3 fix (#1024) * strip file:// * rename test * rename tests * add aiohttp skip * attempt to parse windows paths * test ci * Revert "test ci" This reverts commit 4c1c8a5. * rename test * remove fsspec from test * remove *_handler options * update defaults * do not override default s3 * do not use fsspec for multiprocessing * rename test * fix not selecting object source * missing import * normalize doc * remove helper * never return None as source * remove unnecessary xrootd source default override since fsspec is default now * rename test * add empty class to pass old pickle test * set version to 5.2.0rc1 (release candidate) * set s3fs as default for s3 * test different handlers * correct serialization of fsspec source * feat: simplify object path split (#1028) * simplify object path split * add example from #975 * fix tests * add more test cases * test case update * remove scheme unused regex * feat: fsspec for all non-object writing - %-encoded urls no longer decoded (#1034) * writing goes through fsspec * increase rc version * type hints and docs * add helper methods, create * throw more specific error * add additional test for `create` failure with scheme other than local * simplify source selection * remove windows specific code * raise exception if invalid combination of handler / input (file-like object and fsspec) * use softer check for file-like object * cover problematic case with additional slash (file:///c:/file.root) * test "file:" scheme (no slash) * test backslash * add new test case * split big test in two * retry on socket error * xrootd iterator * iterate over different files * iterate over tree * pytest fixture for test directory * pytest fixture for test directory * add annotation to open argument * remove repeated test
1 parent 32efe97 commit f28ab8b

File tree

5 files changed

+129
-43
lines changed

5 files changed

+129
-43
lines changed

src/uproot/reading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
def open(
28-
path,
28+
path: str | Path | IO | dict[str | Path | IO, str],
2929
*,
3030
object_cache=100,
3131
array_cache="100 MB",

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import contextlib
66
import skhep_testdata
77
from functools import partial
8+
import os
89

910
# The base http server does not support range requests. Watch https://github.com/python/cpython/issues/86809 for updates
1011
from http.server import HTTPServer
@@ -69,3 +70,8 @@ def serve_forever(httpd=server):
6970
def server():
7071
with serve() as server_url:
7172
yield server_url
73+
74+
75+
@pytest.fixture(scope="module")
76+
def tests_directory() -> str:
77+
return os.path.dirname(os.path.realpath(__file__))

tests/test_0520_dynamic_classes_cant_be_abc_subclasses.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import pickle
44
import os
55

6-
import pytest
76

8-
test_directory = os.path.dirname(os.path.realpath(__file__))
9-
10-
11-
def test_pickle():
12-
with open(os.path.join(test_directory, "samples/h_dynamic.pkl"), "rb") as f:
7+
def test_pickle(tests_directory):
8+
with open(os.path.join(tests_directory, "samples/h_dynamic.pkl"), "rb") as f:
139
assert len(list(pickle.load(f).axis(0))) == 100

tests/test_0692_fsspec_reading.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,71 @@ def test_fsspec_zip(tmp_path):
244244
assert len(data) == 40
245245

246246

247+
@pytest.mark.network
248+
@pytest.mark.xrootd
249+
@pytest.mark.parametrize(
250+
"handler",
251+
[
252+
uproot.source.fsspec.FSSpecSource,
253+
uproot.source.xrootd.XRootDSource,
254+
None,
255+
],
256+
)
257+
def test_open_fsspec_xrootd_iterate_files(handler):
258+
pytest.importorskip("XRootD")
259+
260+
iterator = uproot.iterate(
261+
files=[
262+
{
263+
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root": "Events"
264+
},
265+
{
266+
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root": "Events"
267+
},
268+
],
269+
expressions=["run"],
270+
step_size=100,
271+
handler=handler,
272+
)
273+
274+
for i, data in enumerate(iterator):
275+
if i >= 5:
276+
break
277+
assert len(data) == 100
278+
assert all(data["run"] == 194778)
279+
280+
281+
@pytest.mark.network
282+
@pytest.mark.xrootd
283+
@pytest.mark.parametrize(
284+
"handler",
285+
[
286+
uproot.source.fsspec.FSSpecSource,
287+
uproot.source.xrootd.XRootDSource,
288+
None,
289+
],
290+
)
291+
def test_open_fsspec_xrootd_iterate_tree(handler):
292+
pytest.importorskip("XRootD")
293+
294+
with uproot.open(
295+
{
296+
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root": "Events"
297+
},
298+
handler=handler,
299+
) as f:
300+
iterator = f.iterate(
301+
["run"],
302+
step_size=100,
303+
)
304+
305+
for i, data in enumerate(iterator):
306+
if i >= 5:
307+
break
308+
assert len(data) == 100
309+
assert all(data["run"] == 194778)
310+
311+
247312
# https://github.com/scikit-hep/uproot5/issues/1035
248313
@pytest.mark.parametrize(
249314
"handler",

tests/test_0976_path_object_split.py

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,13 @@
1414
"Events",
1515
),
1616
),
17-
(
18-
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
19-
(
20-
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
21-
None,
22-
),
23-
),
2417
(
2518
"github://scikit-hep:[email protected]/src/skhep_testdata/data/uproot-issue121.root:Dir/Events",
2619
(
2720
"github://scikit-hep:[email protected]/src/skhep_testdata/data/uproot-issue121.root",
2821
"Dir/Events",
2922
),
3023
),
31-
(
32-
"github://scikit-hep:[email protected]/src/skhep_testdata/data/uproot-issue121.root",
33-
(
34-
"github://scikit-hep:[email protected]/src/skhep_testdata/data/uproot-issue121.root",
35-
None,
36-
),
37-
),
3824
(
3925
" http://localhost:8080/dir/test.root: Test ",
4026
(
@@ -56,13 +42,6 @@
5642
"Dir/Test",
5743
),
5844
),
59-
(
60-
r"C:\tmp\test\dir\file.root",
61-
(
62-
r"C:\tmp\test\dir\file.root",
63-
None,
64-
),
65-
),
6645
(
6746
"ssh://user@host:22/path/to/file.root:/object//path",
6847
(
@@ -78,10 +57,31 @@
7857
),
7958
),
8059
(
81-
"ssh://user@host:50230/path/to/file.root",
60+
"s3://bucket/path/to/file.root:/dir////object",
8261
(
83-
"ssh://user@host:50230/path/to/file.root",
84-
None,
62+
"s3://bucket/path/to/file.root",
63+
"dir/object",
64+
),
65+
),
66+
(
67+
"s3://bucket/path/to/file.root:",
68+
(
69+
"s3://bucket/path/to/file.root",
70+
"",
71+
),
72+
),
73+
(
74+
"ssh://user@host:22/path/to/file.root:/object//path",
75+
(
76+
"ssh://user@host:22/path/to/file.root",
77+
"object/path",
78+
),
79+
),
80+
(
81+
"ssh://user@host:22/path/to/file.root:/object//path:with:colon:in:path/something/",
82+
(
83+
"ssh://user@host:22/path/to/file.root",
84+
"object/path:with:colon:in:path/something",
8585
),
8686
),
8787
(
@@ -105,11 +105,12 @@
105105
"Events",
106106
),
107107
),
108+
# https://github.com/scikit-hep/uproot5/issues/975
108109
(
109-
"00376186-543E-E311-8D30-002618943857.root",
110+
"DAOD_PHYSLITE_2023-09-13T1230.art.rntuple.root:RNT:CollectionTree",
110111
(
111-
"00376186-543E-E311-8D30-002618943857.root",
112-
None,
112+
"DAOD_PHYSLITE_2023-09-13T1230.art.rntuple.root",
113+
"RNT:CollectionTree",
113114
),
114115
),
115116
# https://github.com/scikit-hep/uproot5/issues/975
@@ -155,13 +156,6 @@
155156
"Events/MET_pt",
156157
),
157158
),
158-
(
159-
"/some/weird/path:with:colons/file.root",
160-
(
161-
"/some/weird/path:with:colons/file.root",
162-
None,
163-
),
164-
),
165159
(
166160
r"C:\tmp\test\dir\my%20file.root:Dir/Test",
167161
(
@@ -178,15 +172,40 @@ def test_url_split(input_value, expected_output):
178172
assert obj == obj_expected
179173

180174

175+
@pytest.mark.parametrize(
176+
"input_value",
177+
[
178+
"/some/weird/path:with:colons/file.root",
179+
"00376186-543E-E311-8D30-002618943857.root",
180+
" file.root",
181+
"dir/file with spaces.root",
182+
"ssh://user@host:50230/path/to/file.root",
183+
r"C:\tmp\test\dir\file.root",
184+
"github://scikit-hep:[email protected]/src/skhep_testdata/data/uproot-issue121.root",
185+
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
186+
"root://xcache.af.uchicago.edu:1094//root://fax.mwt2.org:1094//pnfs/uchicago.edu/atlaslocalgroupdisk/rucio/data18_13TeV/df/a4/DAOD_PHYSLITE.34858087._000001.pool.root.1",
187+
"root://xcacheserver:2222//root://originserver:1111/path/file",
188+
"https://xcacheserver:1111//root[s]://originserver:12222/path/file",
189+
"roots://xcacheserver:2312//https://originserver:3122/path/file",
190+
"http://xcacheserver:8762//https://originserver:4212/path/file",
191+
],
192+
)
193+
def test_url_no_split(input_value):
194+
url, obj = uproot._util.file_object_path_split(input_value)
195+
assert obj is None
196+
assert url == input_value.strip()
197+
198+
181199
@pytest.mark.parametrize(
182200
"input_value",
183201
[
184202
"local/file.root.zip://Events",
185203
"local/file.roo://Events",
186204
"local/file://Events",
205+
"http://xcacheserver:8762//https://originserver:4212/path/file.root.1:CollectionTree",
187206
],
188207
)
189208
def test_url_split_invalid(input_value):
190-
path, obj = uproot._util.file_object_path_split(input_value)
209+
url, obj = uproot._util.file_object_path_split(input_value)
191210
assert obj is None
192-
assert path == input_value
211+
assert url == input_value

0 commit comments

Comments
 (0)