Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Params loading #626

Merged
merged 4 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/integration/test_single_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import pathlib

import pytest
import yaml

import zntrack

Expand Down Expand Up @@ -26,6 +29,23 @@ def test_AddNumbers(proj_path, eager):
assert add_numbers.state.loaded


def test_AddNumbers_remove_params(proj_path):
with zntrack.Project() as project:
add_numbers = AddNumbers(a=1, b=2)

assert not add_numbers.state.loaded

project.run()

params = pathlib.Path("params.yaml").read_text()
params = yaml.safe_load(params)
params[add_numbers.name] = {}
params = pathlib.Path("params.yaml").write_text(yaml.dump(params))

with pytest.raises(zntrack.exceptions.NodeNotAvailableError):
add_numbers.load()


@pytest.mark.parametrize("eager", [True, False])
def test_AddNumbers_named(proj_path, eager):
with zntrack.Project() as project:
Expand Down
2 changes: 1 addition & 1 deletion zntrack/fields/zn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
file = self.get_files(instance)[0]
params_dict = yaml.safe_load(instance.state.fs.read_text(file))
value = params_dict[instance.name].get(self.name, None)
value = params_dict[instance.name][self.name]
return json.loads(json.dumps(value), cls=znjson.ZnDecoder)

def get_stage_add_argument(self, instance: "Node") -> typing.List[tuple]:
Expand Down