33from pyiron_workflow import Workflow , to_function_node
44from python_workflow_definition .pyiron_workflow import load_workflow_json , write_workflow_json
55
6-
6+ function_str = """
77def get_prod_and_div(x, y):
88 return {"prod": x * y, "div": x / y}
99
@@ -14,20 +14,28 @@ def get_sum(x, y):
1414
1515def get_square(x):
1616 return x ** 2
17+ """
1718
1819
1920class TestPyironWorkflow (unittest .TestCase ):
2021 def test_pyiron_workflow (self ):
2122 workflow_json_filename = "pyiron_workflow_arithmetic.json"
22- get_prod_and_div_node = to_function_node ("get_prod_and_div" , get_prod_and_div , "get_prod_and_div" )
23- get_sum_node = to_function_node ("get_sum" , get_sum , "get_sum" )
24- get_square_node = to_function_node ("get_square" , get_square , "get_square" )
23+ with open ("workflow.py" , "w" ) as f :
24+ f .write (function_str )
25+
26+ from workflow import get_prod_and_div as _get_prod_and_div
27+ from workflow import get_sum as _get_sum
28+ from workflow import get_square as _get_square
29+
30+ get_prod_and_div = to_function_node ("get_prod_and_div" , _get_prod_and_div , "get_prod_and_div" )
31+ get_sum = to_function_node ("get_sum" , _get_sum , "get_sum" )
32+ get_square = to_function_node ("get_square" , _get_square , "get_square" )
2533 wf = Workflow ("my_workflow" )
2634 wf .x = 1
2735 wf .y = 2
28- wf .prod_and_div = get_prod_and_div_node (x = wf .x , y = wf .y )
29- wf .tmp_sum = get_sum_node (x = wf .prod_and_div ["prod" ], y = wf .prod_and_div ["div" ])
30- wf .square_result = get_square_node (x = wf .tmp_sum )
36+ wf .prod_and_div = get_prod_and_div (x = wf .x , y = wf .y )
37+ wf .tmp_sum = get_sum (x = wf .prod_and_div ["prod" ], y = wf .prod_and_div ["div" ])
38+ wf .square_result = get_square (x = wf .tmp_sum )
3139 write_workflow_json (graph_as_dict = wf .graph_as_dict , file_name = workflow_json_filename )
3240 wf = load_workflow_json (file_name = workflow_json_filename )
3341 wf .run ()
0 commit comments