Skip to content

Commit

Permalink
Merge pull request #244 from c0fec0de/kylewhite21-devel
Browse files Browse the repository at this point in the history
Kylewhite21 devel
  • Loading branch information
c0fec0de committed Oct 26, 2023
2 parents c45cb46 + e8e99aa commit 4548e7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions anytree/node/symlinknodemixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class SymlinkNodeMixin(NodeMixin):
def __getattr__(self, name):
if name in ("_NodeMixin__parent", "_NodeMixin__children"):
return super(SymlinkNodeMixin, self).__getattr__(name)
if name == "__setstate__":
raise AttributeError(name)
return getattr(self.target, name)

def __setattr__(self, name, value):
Expand Down
29 changes: 29 additions & 0 deletions tests/test_pickle.py
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

0 comments on commit 4548e7c

Please sign in to comment.