Skip to content

Commit

Permalink
test post_load
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Dec 9, 2024
1 parent 24b90ee commit 5a95ef4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/integration/test_post_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import zntrack


class NodeWithPostLoad(zntrack.Node):
params: float = zntrack.params()
outs: float = zntrack.outs()

def _post_load_(self):
self.params += 1

def run(self):
self.outs = self.params


def test_post_load(proj_path):
project = zntrack.Project()
with project:
node = NodeWithPostLoad(params=1)

assert node.params == 1
project.repro()

n = node.from_rev()
assert n.params == 2 # modified by _post_load_
assert n.outs == 1
2 changes: 1 addition & 1 deletion zntrack/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def from_rev(
_ = getattr(instance, field.name)

instance._external_ = True
if hasattr(instance, "_post_load_"):
if not running and hasattr(instance, "_post_load_"):
with contextlib.suppress(NotImplementedError):
instance._post_load_()

Expand Down

0 comments on commit 5a95ef4

Please sign in to comment.