From d473eb266a9a35593e5a01988f2c6ce1daeb2970 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Fri, 6 Nov 2020 16:45:50 -0600 Subject: [PATCH] Complain about missing files, if they're not wildcards. (#184) --- .../test_0182-complain-about-missing-files.py | 23 +++++++++++ uproot4/behaviors/TBranch.py | 41 +++++++++++-------- 2 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 tests/test_0182-complain-about-missing-files.py diff --git a/tests/test_0182-complain-about-missing-files.py b/tests/test_0182-complain-about-missing-files.py new file mode 100644 index 000000000..183251580 --- /dev/null +++ b/tests/test_0182-complain-about-missing-files.py @@ -0,0 +1,23 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE + +from __future__ import absolute_import + +import numpy +import pytest +import skhep_testdata + +import uproot4 + + +def test(): + one = skhep_testdata.data_path("uproot-sample-6.16.00-uncompressed.root") + two = skhep_testdata.data_path("uproot-sample-6.18.00-uncompressed.root") + bad = one.replace(".root", "-DOES-NOT-EXIST.root") + okay = one.replace(".root", "-DOES-NOT-EXIST-*.root") + + assert len(list(uproot4.iterate([one, two], step_size="1 TB"))) == 2 + + with pytest.raises(uproot4._util._FileNotFoundError): + list(uproot4.iterate([one, two, bad])) + + assert len(list(uproot4.iterate([one, two, okay], step_size="1 TB"))) == 2 diff --git a/uproot4/behaviors/TBranch.py b/uproot4/behaviors/TBranch.py index 140224d9e..56dc90e32 100644 --- a/uproot4/behaviors/TBranch.py +++ b/uproot4/behaviors/TBranch.py @@ -2797,6 +2797,7 @@ def _keys_deep(hasbranches): _regularize_files_braces = re.compile(r"{([^}]*,)*([^}]*)}") +_regularize_files_isglob = re.compile(r"[\*\?\[\]{}]") def _regularize_files_inner(files, parse_colon, counter): @@ -2819,25 +2820,29 @@ def _regularize_files_inner(files, parse_colon, counter): else: expanded = os.path.expanduser(file_path) - matches = list(_regularize_files_braces.finditer(expanded)) - if len(matches) == 0: - results = [expanded] + if _regularize_files_isglob.search(expanded) is None: + yield file_path, object_path + else: - results = [] - for combination in itertools.product( - *[match.group(0)[1:-1].split(",") for match in matches] - ): - tmp = expanded - for c, m in list(zip(combination, matches))[::-1]: - tmp = tmp[: m.span()[0]] + c + tmp[m.span()[1] :] - results.append(tmp) - - seen = set() - for result in results: - for match in glob.glob(result): - if match not in seen: - yield match, object_path - seen.add(match) + matches = list(_regularize_files_braces.finditer(expanded)) + if len(matches) == 0: + results = [expanded] + else: + results = [] + for combination in itertools.product( + *[match.group(0)[1:-1].split(",") for match in matches] + ): + tmp = expanded + for c, m in list(zip(combination, matches))[::-1]: + tmp = tmp[: m.span()[0]] + c + tmp[m.span()[1] :] + results.append(tmp) + + seen = set() + for result in results: + for match in glob.glob(result): + if match not in seen: + yield match, object_path + seen.add(match) elif isinstance(files, HasBranches): yield files, None