Skip to content
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
6 changes: 4 additions & 2 deletions fsspec/mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import array
import logging
import posixpath
import uuid
import warnings
from collections.abc import MutableMapping
from functools import cached_property
Expand Down Expand Up @@ -60,8 +61,9 @@ def __init__(self, root, fs, check=False, create=False, missing_exceptions=None)
f"Path {root} does not exist. Create "
f" with the ``create=True`` keyword"
)
self.fs.touch(root + "/a")
self.fs.rm(root + "/a")
check_path = f"{root}/{uuid.uuid4().hex}"
self.fs.touch(check_path)
self.fs.rm(check_path)

@cached_property
def dirfs(self):
Expand Down
13 changes: 13 additions & 0 deletions fsspec/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ def test_mapping_prefix(tmpdir):
assert m == m2 == m3


@pytest.mark.parametrize("protocol", ["file", "memory"])
@pytest.mark.parametrize("key", ["a", "a/nested"])
def test_check_preserves_contents(tmp_path, protocol, key):
url = f"{protocol}://{tmp_path.as_posix()}/mapping"
mapper = fsspec.get_mapper(url, create=True)
contents = {key: b"existing data", "other": b"more data"}
mapper.update(contents)

checked = fsspec.get_mapper(url, check=True)

assert dict(checked) == contents


def test_getitems_errors(tmpdir):
tmpdir = str(tmpdir)
os.makedirs(os.path.join(tmpdir, "afolder"))
Expand Down
Loading