Skip to content

Commit f169fdd

Browse files
Fix failed tests test_attrs() and test_mkdir_with_path() (#479)
* test(core.py): replace HTTP method PATCH with PUT to update object metadata * test(core.py): delete a line that does nothing * test(core.py): partially fix "bucket name already exists" error for `test_mkdir_with_path` * Revert "test(core.py): replace HTTP method PATCH with PUT to update object metadata" This reverts commit 7a7a7d3. * attempts * attempt2 * fix condition * skip instead Co-authored-by: Martin Durant <martin.durant@alumni.utoronto.ca>
1 parent 42aa3dd commit f169fdd

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

gcsfs/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ async def _mkdir(
642642
if "/" in path and create_parents and await self._exists(bucket):
643643
# nothing to do
644644
return
645-
if "/" in path and not create_parents and not await self._exists(bucket):
645+
if "/" in path and not create_parents:
646+
if await self._exists(bucket):
647+
return
646648
raise FileNotFoundError(bucket)
647649

648650
json_data = {"name": bucket}
@@ -798,6 +800,9 @@ async def _setxattrs(
798800
):
799801
"""Set/delete/add writable metadata attributes
800802
803+
Note: uses PATCH method (update), leaving unedited keys alone.
804+
fake-gcs-server:latest does not seem to support this.
805+
801806
Parameters
802807
---------
803808
content_type: str
@@ -843,7 +848,6 @@ async def _setxattrs(
843848
json=i_json,
844849
json_out=True,
845850
)
846-
(await self._info(path))["metadata"] = o_json.get("metadata", {})
847851
return o_json.get("metadata", {})
848852

849853
setxattrs = sync_wrapper(_setxattrs)

gcsfs/tests/test_core.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ def test_array(gcs):
790790

791791

792792
def test_attrs(gcs):
793+
if not gcs.on_google:
794+
# https://github.com/fsspec/gcsfs/pull/479
795+
pytest.skip("fake-gcs-server:latest only supports PUT for metadata, not PATCH")
793796
gcs.touch(a)
794797
assert "metadata" not in gcs.info(a)
795798
with pytest.raises(KeyError):
@@ -1070,12 +1073,15 @@ def test_dir_marker(gcs):
10701073

10711074

10721075
def test_mkdir_with_path(gcs):
1076+
10731077
with pytest.raises(FileNotFoundError):
1074-
gcs.mkdir("new/path", create_parents=False)
1075-
assert not gcs.exists("new")
1076-
gcs.mkdir("new/path", create_parents=True)
1077-
assert gcs.exists("new")
1078+
gcs.mkdir(f"{TEST_BUCKET + 'new'}/path", create_parents=False)
1079+
assert not gcs.exists(f"{TEST_BUCKET + 'new'}")
1080+
gcs.mkdir(f"{TEST_BUCKET + 'new'}/path", create_parents=True)
1081+
assert gcs.exists(f"{TEST_BUCKET + 'new'}")
10781082

10791083
# these lines do nothing, but should not fail
1080-
gcs.mkdir("new/path", create_parents=False)
1081-
gcs.mkdir("new/path", create_parents=True)
1084+
gcs.mkdir(f"{TEST_BUCKET + 'new'}/path", create_parents=False)
1085+
gcs.mkdir(f"{TEST_BUCKET + 'new'}/path", create_parents=True)
1086+
1087+
gcs.rm(f"{TEST_BUCKET + 'new'}", recursive=True)

0 commit comments

Comments
 (0)