-
-
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.
* change serializer * move definition out of __init__ * fix typo * keep `value` key in `zntrack.json` * add check for backwards compatibility * use fixture * review comments
- Loading branch information
Showing
8 changed files
with
443 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import json | ||
import os | ||
import pathlib | ||
import shutil | ||
import subprocess | ||
|
||
import pytest | ||
|
||
from zntrack import zn | ||
from zntrack.core.base import Node | ||
|
||
|
||
@pytest.fixture | ||
def proj_path(tmp_path): | ||
shutil.copy(__file__, tmp_path) | ||
os.chdir(tmp_path) | ||
subprocess.check_call(["git", "init"]) | ||
subprocess.check_call(["dvc", "init"]) | ||
|
||
return tmp_path | ||
|
||
|
||
class FirstNode(Node): | ||
outs = zn.outs() | ||
|
||
def run(self): | ||
self.outs = 42 | ||
|
||
|
||
class LastNode(Node): | ||
first_node: FirstNode = zn.deps(FirstNode.load()) | ||
outs = zn.outs() | ||
|
||
def run(self): | ||
self.outs = self.first_node.outs / 2 | ||
|
||
|
||
def test_base_run(proj_path): | ||
FirstNode().write_graph(run=True) | ||
LastNode().write_graph(run=True) | ||
|
||
assert LastNode.load().outs == 21 | ||
|
||
|
||
@pytest.fixture() | ||
def zntrack_dict() -> dict: | ||
return { | ||
"LastNode": { | ||
"first_node": { | ||
"_type": "ZnTrackType", | ||
"value": { | ||
"cls": "FirstNode", | ||
"module": "test_zn_deps", | ||
"name": "FirstNode", | ||
}, | ||
} | ||
} | ||
} | ||
|
||
|
||
def test_assert_write_file(proj_path, zntrack_dict): | ||
FirstNode().write_graph() | ||
LastNode().write_graph() | ||
|
||
zntrack_dict_loaded = json.loads(pathlib.Path("zntrack.json").read_text()) | ||
|
||
assert zntrack_dict_loaded == zntrack_dict | ||
|
||
|
||
def test_assert_read_file(proj_path, zntrack_dict): | ||
pathlib.Path("zntrack.json").write_text(json.dumps(zntrack_dict)) | ||
|
||
assert isinstance(LastNode.load().first_node, FirstNode) |
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
Oops, something went wrong.