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
2 changes: 2 additions & 0 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,8 @@ def from_dict(dct: Dict[str, Any]) -> AbstractFileSystem:
"""
from .json import FilesystemJSONDecoder

dct = dict(dct) # Defensive copy

cls = FilesystemJSONDecoder.try_resolve_fs_cls(dct)
if cls is None:
raise ValueError("Not a serialized AbstractFileSystem")
Expand Down
24 changes: 24 additions & 0 deletions fsspec/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,30 @@ def test_json_fs_attr():
assert DummyTestFS.from_json(outb) is b


def test_dict():
a = DummyTestFS(1)
b = DummyTestFS(2, bar=1)

outa = a.to_dict()
outb = b.to_dict()

assert isinstance(outa, dict)
assert a != b
assert "bar" in outb

assert DummyTestFS.from_dict(outa) is a
assert DummyTestFS.from_dict(outb) is b


def test_dict_idempotent():
a = DummyTestFS(1)

outa = a.to_dict()

assert DummyTestFS.from_dict(outa) is a
assert DummyTestFS.from_dict(outa) is a


def test_from_dict_valid():
fs = DummyTestFS.from_dict({"cls": "fsspec.tests.test_spec.DummyTestFS"})
assert isinstance(fs, DummyTestFS)
Expand Down