Skip to content

Commit

Permalink
Add tests to ls kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreLobato committed Dec 9, 2024
1 parent 3977045 commit f8292b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 3 additions & 4 deletions oceanum/storage/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,12 @@ async def _ls(self,
params["file_prefix"] = file_prefix
if match_glob:
params["match_glob"] = match_glob

async with session.get(self._base_url + spath, params=params or None) as r:
try:
self._raise_not_found_for_status(r, path)
except (
FileNotFoundError
): # The storage endpoint enforces trailing slash for directories, so test for that
except FileNotFoundError:
# The storage endpoint enforces trailing slash for directories, so test for that
if path.endswith("/"):
raise FileNotFoundError(path)
else:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ def test_ls(fs, dummy_files):
paths = list(fs.walk(REMOTE_PATH))
assert len(paths) == 2

def test_ls_file_prefix(fs, dummy_files):
test_folder = f'{REMOTE_PATH}/test'
fs.mkdirs(test_folder, exist_ok=True)
fs.put(dummy_files.name, test_folder, recursive=True)
files = fs.ls(test_folder, file_prefix="file1")
assert len(files) == 1
assert files[0]["name"] == "test_storage/test/file1.txt"

def test_ls_glob(fs, dummy_files):
test_folder = f'{REMOTE_PATH}/test'
fs.mkdirs(test_folder, exist_ok=True)
fs.put(dummy_files.name, test_folder, recursive=True)
files = fs.ls(test_folder, match_glob="**/*2.txt")
assert len(files) == 1
assert files[0]["name"] == "test_storage/test/file2.txt"

def test_ls_limit(fs, dummy_files):
test_folder = f'{REMOTE_PATH}/test'
fs.mkdirs(test_folder, exist_ok=True)
fs.put(dummy_files.name, test_folder, recursive=True)
# Something is off with limit
# At the storage API level, it returns 1 file when limit=2
files = fs.ls(test_folder, limit=2)
assert len(files) == 1
assert files[0]["name"] == "test_storage/test/file1.txt"

def test_get(fs, dummy_files):
fs.mkdirs(REMOTE_PATH, exist_ok=True)
Expand Down

0 comments on commit f8292b9

Please sign in to comment.