Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
write functions to file
  • Loading branch information
jan-janssen committed Jan 9, 2026
commit 1c922116519bbaf86ecb520ef53eda13c5e5f04b
22 changes: 15 additions & 7 deletions tests/test_pyiron_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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()
Expand Down
Loading