Skip to content

Commit

Permalink
Better double asterisk support (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-jam authored Aug 24, 2023
1 parent 1758134 commit 54eaa80
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ async def _find(

if maxdepth:
# Filter returned objects based on requested maxdepth
depth = path.count("/") + maxdepth
depth = path.rstrip("/").count("/") + maxdepth
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/")
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

0 comments on commit 54eaa80

Please sign in to comment.