@@ -52,3 +52,76 @@ def test_dynamic_launch_plan_yielding():
52
52
assert dj_spec .outputs [0 ].var == "out"
53
53
assert dj_spec .outputs [0 ].binding .promise .node_id == node_id
54
54
assert dj_spec .outputs [0 ].binding .promise .var == "task_output"
55
+
56
+
57
+ @_tasks .python_task
58
+ def empty_task (wf_params ):
59
+ wf_params .logging .info ("Running empty task" )
60
+
61
+
62
+ @_workflow .workflow_class ()
63
+ class EmptyWorkflow (object ):
64
+ empty_task_task_execution = empty_task ()
65
+
66
+
67
+ constant_workflow_lp = EmptyWorkflow .create_launch_plan ()
68
+
69
+
70
+ @_tasks .outputs (out = _Types .Integer )
71
+ @_tasks .dynamic_task
72
+ def lp_yield_empty_wf (wf_params , out ):
73
+ wf_params .logging .info ("Running inner task... yielding a launchplan for empty workflow" )
74
+ constant_lp_yielding_task_execution = constant_workflow_lp ()
75
+ yield constant_lp_yielding_task_execution
76
+ out .set (42 )
77
+
78
+
79
+ def test_dynamic_launch_plan_yielding_of_constant_workflow ():
80
+ outputs = lp_yield_empty_wf .unit_test ()
81
+ # TODO: Currently, Flytekit will not return early and not do anything if there are any workflow nodes detected
82
+ # in the output of a dynamic task.
83
+ dj_spec = outputs [_sdk_constants .FUTURES_FILE_NAME ]
84
+
85
+ assert len (dj_spec .nodes ) == 1
86
+ assert len (dj_spec .outputs ) == 1
87
+ assert dj_spec .outputs [0 ].var == "out"
88
+ assert len (outputs .keys ()) == 1
89
+
90
+
91
+ @_tasks .inputs (num = _Types .Integer )
92
+ @_tasks .python_task
93
+ def log_only_task (wf_params , num ):
94
+ wf_params .logging .info ("{} was called" .format (num ))
95
+
96
+
97
+ @_workflow .workflow_class ()
98
+ class InputOnlyWorkflow (object ):
99
+ a = _workflow .Input (_Types .Integer , default = 5 , help = "Input for inner workflow" )
100
+ log_only_task_execution = log_only_task (num = a )
101
+
102
+
103
+ input_only_workflow_lp = InputOnlyWorkflow .create_launch_plan ()
104
+
105
+
106
+ @_tasks .dynamic_task
107
+ def lp_yield_input_only_wf (wf_params ):
108
+ wf_params .logging .info ("Running inner task... yielding a launchplan for input only workflow" )
109
+ input_only_workflow_lp_execution = input_only_workflow_lp ()
110
+ yield input_only_workflow_lp_execution
111
+
112
+
113
+ def test_dynamic_launch_plan_yielding_of_input_only_workflow ():
114
+ outputs = lp_yield_input_only_wf .unit_test ()
115
+ # TODO: Currently, Flytekit will not return early and not do anything if there are any workflow nodes detected
116
+ # in the output of a dynamic task.
117
+ dj_spec = outputs [_sdk_constants .FUTURES_FILE_NAME ]
118
+
119
+ assert len (dj_spec .nodes ) == 1
120
+ assert len (dj_spec .outputs ) == 0
121
+ assert len (outputs .keys ()) == 2
122
+
123
+ # Using the id of the launch plan node, and then appending /inputs.pb to the string, should give you in the outputs
124
+ # map the LiteralMap of the inputs of that node
125
+ input_key = "{}/inputs.pb" .format (dj_spec .nodes [0 ].id )
126
+ lp_input_map = outputs [input_key ]
127
+ assert lp_input_map .literals ['a' ] is not None
0 commit comments