-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add_operating_directory
- Loading branch information
Showing
12 changed files
with
324 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,59 @@ | ||
import pytest | ||
|
||
import zntrack | ||
|
||
|
||
class GenerateList(zntrack.Node): | ||
size = zntrack.zn.params(10) | ||
outs = zntrack.zn.outs() | ||
|
||
def run(self): | ||
self.outs = list(range(self.size)) | ||
|
||
|
||
class AddOneToList(zntrack.Node): | ||
data = zntrack.zn.deps() | ||
outs = zntrack.zn.outs() | ||
|
||
def run(self) -> None: | ||
self.outs = [x + 1 for x in self.data] | ||
|
||
|
||
class AddOneToDict(zntrack.Node): | ||
data = zntrack.zn.deps() | ||
outs = zntrack.zn.outs() | ||
|
||
def run(self) -> None: | ||
self.outs = {k: [x + 1 for x in v] for k, v in self.data.items()} | ||
|
||
|
||
@pytest.mark.parametrize("eager", [True, False]) | ||
def test_combine(proj_path, eager): | ||
with zntrack.Project() as proj: | ||
a = GenerateList(size=1, name="a") | ||
b = GenerateList(size=2, name="b") | ||
c = GenerateList(size=3, name="c") | ||
|
||
added = AddOneToList(data=a.outs + b.outs + c.outs) | ||
|
||
proj.run(eager=eager) | ||
if not eager: | ||
added.load() | ||
|
||
assert added.outs == [1] + [1, 2] + [1, 2, 3] | ||
|
||
|
||
@pytest.mark.parametrize("eager", [True, False]) | ||
def test_combine_dict(proj_path, eager): | ||
with zntrack.Project() as proj: | ||
a = GenerateList(size=1, name="a") | ||
b = GenerateList(size=2, name="b") | ||
c = GenerateList(size=3, name="c") | ||
|
||
added = AddOneToDict(data={x.name: x.outs for x in [a, b, c]}) | ||
|
||
proj.run(eager=eager) | ||
if not eager: | ||
added.load() | ||
|
||
assert added.outs == {"a": [1], "b": [1, 2], "c": [1, 2, 3]} |
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,26 @@ | ||
import znflow | ||
|
||
import zntrack | ||
|
||
|
||
class NodeWithProperty(zntrack.Node): | ||
params = zntrack.zn.params(None) | ||
|
||
@property | ||
def calc(self): | ||
"""This should not change the params if not called.""" | ||
self.params = 42 | ||
return "calc" | ||
|
||
def run(self): | ||
pass | ||
|
||
|
||
def test_NodeWithProperty(proj_path): | ||
with zntrack.Project() as proj: | ||
node = NodeWithProperty() | ||
|
||
proj.run() | ||
|
||
node.load() | ||
assert node.params is None |
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
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,19 @@ | ||
"""All ZnTrack exceptions.""" | ||
|
||
|
||
class NodeNotAvailableError(Exception): | ||
"""Raised when a node is not available.""" | ||
|
||
def __init__(self, arg): | ||
"""Initialize the exception. | ||
Parameters | ||
---------- | ||
arg : str|Node | ||
Custom Error message or Node that is not available. | ||
""" | ||
if isinstance(arg, str): | ||
super().__init__(arg) | ||
else: | ||
# assume arg is a Node | ||
super().__init__(f"Node {arg.name} is not available.") |
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
Oops, something went wrong.