Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better double asterisk support #572

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ async def _find(

if maxdepth:
# Filter returned objects based on requested maxdepth
depth = path.count("/") + maxdepth
depth = path.rstrip("/").count("/") + maxdepth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The depth is wrong when there is a trailing slash in the source path. We could also strip it at the very beginning of the _find method (the tests also works).

objects = list(filter(lambda o: o["name"].count("/") <= depth, objects))

if detail:
Expand Down
Empty file added gcsfs/tests/derived/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions gcsfs/tests/derived/gcsfs_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fsspec
import pytest
from fsspec.tests.abstract import AbstractFixtures

from gcsfs.core import GCSFileSystem
from gcsfs.tests.conftest import allfiles
from gcsfs.tests.settings import TEST_BUCKET


class GcsfsFixtures(AbstractFixtures):
@pytest.fixture(scope="class")
def fs(self, docker_gcs):
GCSFileSystem.clear_instance_cache()
gcs = fsspec.filesystem("gcs", endpoint_url=docker_gcs)
try:
# ensure we're empty.
try:
gcs.rm(TEST_BUCKET, recursive=True)
except FileNotFoundError:
pass
try:
gcs.mkdir(TEST_BUCKET)
except Exception:
pass

gcs.pipe({TEST_BUCKET + "/" + k: v for k, v in allfiles.items()})
gcs.invalidate_cache()
yield gcs
finally:
try:
gcs.rm(gcs.find(TEST_BUCKET))
gcs.rm(TEST_BUCKET)
except: # noqa: E722
pass

@pytest.fixture
def fs_path(self):
return TEST_BUCKET

@pytest.fixture
def supports_empty_directories(self):
return False
15 changes: 15 additions & 0 deletions gcsfs/tests/derived/gcsfs_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fsspec.tests.abstract as abstract

from gcsfs.tests.derived.gcsfs_fixtures import GcsfsFixtures


class TestGcsfsCopy(abstract.AbstractCopyTests, GcsfsFixtures):
pass


class TestGcsfsGet(abstract.AbstractGetTests, GcsfsFixtures):
pass


class TestGcsfsPut(abstract.AbstractPutTests, GcsfsFixtures):
pass
2 changes: 1 addition & 1 deletion gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_gcs_glob(gcs):
fn = TEST_BUCKET + "/nested/file1"
assert fn not in gcs.glob(TEST_BUCKET + "/")
assert fn not in gcs.glob(TEST_BUCKET + "/*")
assert fn in gcs.glob(TEST_BUCKET + "/nested/")
assert fn not in gcs.glob(TEST_BUCKET + "/nested/")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing slashes in globs now returns only the directories.

assert fn in gcs.glob(TEST_BUCKET + "/nested/*")
assert fn in gcs.glob(TEST_BUCKET + "/nested/file*")
assert fn in gcs.glob(TEST_BUCKET + "/*/*")
Expand Down
Loading