From ad6c3e28ebd41b0f8eed840ffabf5860f68dd102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Fri, 9 Jan 2026 06:55:37 +0100 Subject: [PATCH 1/2] Add pyiron_workflow test --- tests/test_pyiron_workflow.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_pyiron_workflow.py diff --git a/tests/test_pyiron_workflow.py b/tests/test_pyiron_workflow.py new file mode 100644 index 0000000..3345949 --- /dev/null +++ b/tests/test_pyiron_workflow.py @@ -0,0 +1,35 @@ +import unittest +import os +from pyiron_workflow import Workflow, to_function_node +from python_workflow_definition.pyiron_workflow import load_workflow_json, write_workflow_json + + +def get_prod_and_div(x, y): + return {"prod": x * y, "div": x / y} + + +def get_sum(x, y): + return x + y + + +def get_square(x): + return x ** 2 + + +class TestPyironWorkflow(unittest.TestCase): + def test_pyiron_workflow(self): + workflow_json_filename = "pyiron_workflow_arithmetic.json" + get_prod_and_div_node = to_function_node("get_prod_and_div", get_prod_and_div, "get_prod_and_div") + get_sum_node = to_function_node("get_sum", get_sum, "get_sum") + get_square_node = to_function_node("get_square", get_square, "get_square") + wf = Workflow("my_workflow") + wf.x = 1 + wf.y = 2 + wf.prod_and_div = get_prod_and_div_node(x=wf.x, y=wf.y) + wf.tmp_sum = get_sum_node(x=wf.prod_and_div["prod"], y=wf.prod_and_div["div"]) + wf.square_result = get_square_node(x=wf.tmp_sum) + write_workflow_json(graph_as_dict=wf.graph_as_dict, file_name=workflow_json_filename) + wf = load_workflow_json(file_name=workflow_json_filename) + wf.run() + + self.assertTrue(os.path.exists(workflow_json_filename)) From 1c922116519bbaf86ecb520ef53eda13c5e5f04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Fri, 9 Jan 2026 07:10:29 +0100 Subject: [PATCH 2/2] write functions to file --- tests/test_pyiron_workflow.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/test_pyiron_workflow.py b/tests/test_pyiron_workflow.py index 3345949..cbeb836 100644 --- a/tests/test_pyiron_workflow.py +++ b/tests/test_pyiron_workflow.py @@ -3,7 +3,7 @@ from pyiron_workflow import Workflow, to_function_node from python_workflow_definition.pyiron_workflow import load_workflow_json, write_workflow_json - +function_str = """ def get_prod_and_div(x, y): return {"prod": x * y, "div": x / y} @@ -14,20 +14,28 @@ def get_sum(x, y): def get_square(x): return x ** 2 +""" class TestPyironWorkflow(unittest.TestCase): def test_pyiron_workflow(self): workflow_json_filename = "pyiron_workflow_arithmetic.json" - get_prod_and_div_node = to_function_node("get_prod_and_div", get_prod_and_div, "get_prod_and_div") - get_sum_node = to_function_node("get_sum", get_sum, "get_sum") - get_square_node = to_function_node("get_square", get_square, "get_square") + with open("workflow.py", "w") as f: + f.write(function_str) + + from workflow import get_prod_and_div as _get_prod_and_div + from workflow import get_sum as _get_sum + from workflow import get_square as _get_square + + get_prod_and_div = to_function_node("get_prod_and_div", _get_prod_and_div, "get_prod_and_div") + get_sum = to_function_node("get_sum", _get_sum, "get_sum") + get_square = to_function_node("get_square", _get_square, "get_square") wf = Workflow("my_workflow") wf.x = 1 wf.y = 2 - wf.prod_and_div = get_prod_and_div_node(x=wf.x, y=wf.y) - wf.tmp_sum = get_sum_node(x=wf.prod_and_div["prod"], y=wf.prod_and_div["div"]) - wf.square_result = get_square_node(x=wf.tmp_sum) + wf.prod_and_div = get_prod_and_div(x=wf.x, y=wf.y) + wf.tmp_sum = get_sum(x=wf.prod_and_div["prod"], y=wf.prod_and_div["div"]) + wf.square_result = get_square(x=wf.tmp_sum) write_workflow_json(graph_as_dict=wf.graph_as_dict, file_name=workflow_json_filename) wf = load_workflow_json(file_name=workflow_json_filename) wf.run()