-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow for roundtrips of cloudpaths through pickle serialization (#454) This avoids an exception thrown because the _client is not serialized into the pickled object, and thus when __getstate__ is called the second time, there is no _client field to delete. Closes #450 * pickle tests --------- Co-authored-by: Aaron Taylor <[email protected]>
- Loading branch information
Showing
4 changed files
with
35 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pickle | ||
|
||
from cloudpathlib import CloudPath | ||
|
||
|
||
def test_pickle(rig, tmpdir): | ||
p = rig.create_cloud_path("dir_0/file0_0.txt") | ||
|
||
with (tmpdir / "test.pkl").open("wb") as f: | ||
pickle.dump(p, f) | ||
|
||
with (tmpdir / "test.pkl").open("rb") as f: | ||
pickled = pickle.load(f) | ||
|
||
# test a call to the network | ||
assert pickled.exists() | ||
|
||
# check we unpickled, and that client is the default client | ||
assert str(pickled) == str(p) | ||
assert pickled.client == p.client | ||
assert rig.client_class._default_client == pickled.client | ||
|
||
|
||
def test_pickle_roundtrip(): | ||
path1 = CloudPath("s3://bucket/key") | ||
pkl1 = pickle.dumps(path1) | ||
|
||
path2 = pickle.loads(pkl1) | ||
pkl2 = pickle.dumps(path2) | ||
|
||
assert path1 == path2 | ||
assert pkl1 == pkl2 |