-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from c0fec0de/kylewhite21-devel
Kylewhite21 devel
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
import pickle | ||
|
||
from anytree import AnyNode, LoopError, Node, NodeMixin, PostOrderIter, PreOrderIter, RenderTree, SymlinkNode, TreeError | ||
|
||
|
||
def test_pickle(tmp_path): | ||
"""Pickling Compatibilty.""" | ||
root = Node(name="root") | ||
a = Node(name="a", parent=root) | ||
b = Node(name="b", parent=a) | ||
c = SymlinkNode(target=b, parent=a) | ||
|
||
lines = str(RenderTree(root)).splitlines() | ||
assert lines == [ | ||
"Node('/root')", | ||
"└── Node('/root/a')", | ||
" ├── Node('/root/a/b')", | ||
" └── SymlinkNode(Node('/root/a/b'))", | ||
] | ||
|
||
filepath = tmp_path / "test.pkl" | ||
with open(filepath, "wb") as file: | ||
pickle.dump(root, file) | ||
|
||
with open(filepath, "rb") as file: | ||
loaded = pickle.load(file) | ||
|
||
assert str(RenderTree(root)).splitlines() == lines |