Skip to content

Commit

Permalink
Merge pull request fsspec#507 from earthobservations/fix-random-direc…
Browse files Browse the repository at this point in the history
…tory

Fix appending of random directory within find() method
  • Loading branch information
martindurant committed Jan 2, 2021
2 parents 0b39f03 + d26e6c3 commit f33cdf9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/source/changelog.rst
@@ -1,6 +1,13 @@
Changelog
=========

Dev
-------------

Fixes:

- random appending of a directory within the filesystems ``find()`` method

Version 0.8.5
-------------

Expand Down
2 changes: 1 addition & 1 deletion fsspec/spec.py
Expand Up @@ -427,7 +427,7 @@ def find(self, path, maxdepth=None, withdirs=False, **kwargs):
path = self._strip_protocol(path)
out = dict()
detail = kwargs.pop("detail", False)
for path, dirs, files in self.walk(path, maxdepth, detail=True, **kwargs):
for _, dirs, files in self.walk(path, maxdepth, detail=True, **kwargs):
if withdirs:
files.update(dirs)
out.update({info["name"]: info for name, info in files.items()})
Expand Down
52 changes: 52 additions & 0 deletions fsspec/tests/test_spec.py
Expand Up @@ -6,6 +6,7 @@

import fsspec
from fsspec.implementations.ftp import FTPFileSystem
from fsspec.implementations.http import HTTPFileSystem
from fsspec.spec import AbstractFileSystem, AbstractBufferedFile


Expand Down Expand Up @@ -178,6 +179,57 @@ def test_expand_path_recursive(test_paths, expected):
assert sorted(paths) == sorted(expected)


@pytest.mark.parametrize(
["filesystem", "host", "test_path", "expected"],
[
(
FTPFileSystem,
"ftp.fau.de",
"ftp://ftp.fau.de/debian-cd/current/amd64/log/success",
[
"/debian-cd/current/amd64/log/success/BD.log",
"/debian-cd/current/amd64/log/success/DLBD.log",
"/debian-cd/current/amd64/log/success/DVD.log",
"/debian-cd/current/amd64/log/success/EDUNI.log",
"/debian-cd/current/amd64/log/success/EDUUSB.log",
"/debian-cd/current/amd64/log/success/MACNI.log",
"/debian-cd/current/amd64/log/success/NI.log",
"/debian-cd/current/amd64/log/success/USB16G.log",
"/debian-cd/current/amd64/log/success/XFCECD.log",
],
),
(
HTTPFileSystem,
"https://ftp.fau.de",
"https://ftp.fau.de/debian-cd/current/amd64/log/success",
[
"https://ftp.fau.de/debian-cd/current/amd64/log/success",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/?C=D;O=A",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/?C=M;O=A",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/?C=N;O=D",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/?C=S;O=A",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/BD.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/DLBD.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/DVD.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/EDUNI.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/EDUUSB.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/MACNI.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/NI.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/USB16G.log",
"https://ftp.fau.de/debian-cd/current/amd64/log/success/XFCECD.log",
],
),
],
)
def test_find(filesystem, host, test_path, expected):
""" Test .find() method on debian server (available as ftp and https) with constant folder """
test_fs = filesystem(host)

filenames = test_fs.find(test_path)

assert filenames == expected


def test_find_details():
test_fs = DummyTestFS()
filenames = test_fs.find("/")
Expand Down

0 comments on commit f33cdf9

Please sign in to comment.