File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1470,6 +1470,8 @@ def from_dict(dct: Dict[str, Any]) -> AbstractFileSystem:
1470
1470
"""
1471
1471
from .json import FilesystemJSONDecoder
1472
1472
1473
+ dct = dict (dct ) # Defensive copy
1474
+
1473
1475
cls = FilesystemJSONDecoder .try_resolve_fs_cls (dct )
1474
1476
if cls is None :
1475
1477
raise ValueError ("Not a serialized AbstractFileSystem" )
Original file line number Diff line number Diff line change @@ -888,6 +888,30 @@ def test_json_fs_attr():
888
888
assert DummyTestFS .from_json (outb ) is b
889
889
890
890
891
+ def test_dict ():
892
+ a = DummyTestFS (1 )
893
+ b = DummyTestFS (2 , bar = 1 )
894
+
895
+ outa = a .to_dict ()
896
+ outb = b .to_dict ()
897
+
898
+ assert isinstance (outa , dict )
899
+ assert a != b
900
+ assert "bar" in outb
901
+
902
+ assert DummyTestFS .from_dict (outa ) is a
903
+ assert DummyTestFS .from_dict (outb ) is b
904
+
905
+
906
+ def test_dict_idempotent ():
907
+ a = DummyTestFS (1 )
908
+
909
+ outa = a .to_dict ()
910
+
911
+ assert DummyTestFS .from_dict (outa ) is a
912
+ assert DummyTestFS .from_dict (outa ) is a
913
+
914
+
891
915
def test_from_dict_valid ():
892
916
fs = DummyTestFS .from_dict ({"cls" : "fsspec.tests.test_spec.DummyTestFS" })
893
917
assert isinstance (fs , DummyTestFS )
You can’t perform that action at this time.
0 commit comments