1313def test_node_protocol_for_custom_nodes (runner , tmp_path ):
1414 source = """
1515 from typing import Annotated
16+ from typing import Any
1617 from pytask import Product
1718 from attrs import define
1819 from pathlib import Path
@@ -22,6 +23,7 @@ class CustomNode:
2223 name: str
2324 value: str
2425 signature: str = "id"
26+ attributes: dict[Any, Any] = {}
2527
2628 def state(self):
2729 return self.value
@@ -43,12 +45,14 @@ def task_example(
4345 result = runner .invoke (cli , [tmp_path .as_posix ()])
4446 assert result .exit_code == ExitCode .OK
4547 assert tmp_path .joinpath ("out.txt" ).read_text () == "text"
48+ assert "FutureWarning" not in result .output
4649
4750
4851@pytest .mark .end_to_end
4952def test_node_protocol_for_custom_nodes_with_paths (runner , tmp_path ):
5053 source = """
5154 from typing import Annotated
55+ from typing import Any
5256 from pytask import Product
5357 from pathlib import Path
5458 from attrs import define
@@ -60,6 +64,7 @@ class PickleFile:
6064 path: Path
6165 value: Path
6266 signature: str = "id"
67+ attributes: dict[Any, Any] = {}
6368
6469 def state(self):
6570 return str(self.path.stat().st_mtime)
@@ -87,3 +92,40 @@ def task_example(
8792 result = runner .invoke (cli , [tmp_path .as_posix ()])
8893 assert result .exit_code == ExitCode .OK
8994 assert tmp_path .joinpath ("out.txt" ).read_text () == "text"
95+
96+
97+ @pytest .mark .end_to_end
98+ def test_node_protocol_for_custom_nodes_adding_attributes (runner , tmp_path ):
99+ source = """
100+ from typing import Annotated
101+ from pytask import Product
102+ from attrs import define
103+ from pathlib import Path
104+
105+ @define
106+ class CustomNode:
107+ name: str
108+ value: str
109+ signature: str = "id"
110+
111+ def state(self):
112+ return self.value
113+
114+ def load(self, is_product):
115+ return self.value
116+
117+ def save(self, value):
118+ self.value = value
119+
120+ def task_example(
121+ data = CustomNode("custom", "text"),
122+ out: Annotated[Path, Product] = Path("out.txt"),
123+ ) -> None:
124+ out.write_text(data)
125+ """
126+ tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
127+
128+ result = runner .invoke (cli , [tmp_path .as_posix ()])
129+ assert result .exit_code == ExitCode .OK
130+ assert tmp_path .joinpath ("out.txt" ).read_text () == "text"
131+ assert "FutureWarning" in result .output
0 commit comments