Skip to content

Commit

Permalink
Test the new glob_funcs and match their output to standard python glob
Browse files Browse the repository at this point in the history
  • Loading branch information
benkrikler committed Apr 24, 2019
1 parent 234f233 commit 3afe945
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
9 changes: 4 additions & 5 deletions bindings/python/libs/client/glob_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def glob(pathname):
if try_glob:
return try_glob

# If pathname does not contain a wildcard:
if not gl.has_magic(pathname):
return [pathname]

# Else try xrootd instead
return xrootd_glob(pathname)

Expand All @@ -76,7 +72,10 @@ def xrootd_glob(pathname):
if not query:
raise RuntimeError("Cannot prepare xrootd query")

_, dirlist = query.dirlist(path)
status, dirlist = query.dirlist(path)
if status.error:
continue

for entry in dirlist.dirlist:
filename = entry.name
if filename in [".", ".."]:
Expand Down
34 changes: 34 additions & 0 deletions bindings/python/tests/test_glob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
import glob as norm_glob
import XRootD.client.glob_funcs as glob
from pathlib2 import Path


@pytest.fixture
def tmptree(tmpdir):
subdir1 = tmpdir / "subdir1"
subdir1.mkdir()
subdir2 = tmpdir / "subdir2"
subdir2.mkdir()
for i in range(3):
dummy = subdir1 / ("a_file_%d.txt" % i)
dummy.write_text(u"This is file %d\n" % i, encoding="utf-8")
return tmpdir


def test_local_glob(tmptree):
assert len(glob.glob(str(tmptree / "not-there"))) == 0
assert len(glob.glob(str(tmptree / "not-there*"))) == 0
assert len(glob.glob(str(tmptree / "sub*"))) == 2
assert len(glob.glob(str(tmptree / "subdir1" / "*txt"))) == 3
assert len(glob.glob(str(tmptree / "subdir*" / "*txt"))) == 3


def test_xrootd_glob(tmptree):
tmptree = Path("root://localhost:") / tmptree
assert glob.glob(str(tmptree / "not-there")) == norm_glob.glob(str(tmptree / "not-there"))
assert len(glob.glob(str(tmptree / "not-there"))) == 0
assert len(glob.glob(str(tmptree / "not-there*"))) == 0
assert len(glob.glob(str(tmptree / "sub*"))) == 2
assert len(glob.glob(str(tmptree / "subdir1" / "*txt"))) == 3
assert len(glob.glob(str(tmptree / "subdir*" / "*txt"))) == 3

0 comments on commit 3afe945

Please sign in to comment.