Skip to content

Commit 4b75b3f

Browse files
committed
🧪 tests: prepare testcase for message change.
1 parent 9317930 commit 4b75b3f

13 files changed

+309
-91
lines changed

src/ddeutil/workflow/result.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ class Layer(str, Enum):
323323

324324

325325
def get_context_by_layer(
326-
context: DictData, key: str, layer: Layer, context_key: str
326+
context: DictData,
327+
key: str,
328+
layer: Layer,
329+
context_key: str,
327330
):
328331
if layer == Layer.WORKFLOW:
329332
return context.get("jobs", {}).get(key, {}).get(context_key, WAIT)

src/ddeutil/workflow/stages.py

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ def __prepare_running_id(self) -> Self:
235235
return self
236236

237237
def pass_template(self, value: Any, params: DictData) -> Any:
238+
"""Pass template and environment variable to any value that can
239+
templating.
240+
241+
Args:
242+
value (Any): An any value.
243+
params (DictData):
244+
245+
Returns:
246+
Any: A templated value.
247+
"""
238248
return pass_env(param2template(value, params, extras=self.extras))
239249

240250
@abstractmethod
@@ -499,10 +509,12 @@ def get_outputs(self, output: DictData) -> DictData:
499509
"""Get the outputs from stages data. It will get this stage ID from
500510
the stage outputs mapping.
501511
502-
:param output: (DictData) A stage output context that want to get this
503-
stage ID `outputs` key.
512+
Args:
513+
output (DictData): A stage output context that want to get this
514+
stage ID `outputs` key.
504515
505-
:rtype: DictData
516+
Returns:
517+
DictData: An output value that have get with its identity.
506518
"""
507519
if self.id is None and not dynamic(
508520
"stage_default_id", extras=self.extras
@@ -1066,9 +1078,7 @@ def process(
10661078
)
10671079

10681080
if event and event.is_set():
1069-
raise StageCancelError(
1070-
"Execution was canceled from the event before start parallel."
1071-
)
1081+
raise StageCancelError("Cancel before start empty process.")
10721082

10731083
trace.info(f"[STAGE]: Message: ( {message} )")
10741084
if self.sleep > 0:
@@ -1119,9 +1129,7 @@ async def async_process(
11191129
)
11201130

11211131
if event and event.is_set():
1122-
raise StageCancelError(
1123-
"Execution was canceled from the event before start parallel."
1124-
)
1132+
raise StageCancelError("Cancel before start empty process.")
11251133

11261134
trace.info(f"[STAGE]: Message: ( {message} )")
11271135
if self.sleep > 0:
@@ -1759,9 +1767,7 @@ def process(
17591767
args.pop("extras")
17601768

17611769
if event and event.is_set():
1762-
raise StageCancelError(
1763-
"Execution was canceled from the event before start parallel."
1764-
)
1770+
raise StageCancelError("Cancel before start call process.")
17651771

17661772
args: DictData = self.validate_model_args(
17671773
call_func, args, run_id, parent_run_id, extras=self.extras
@@ -1879,9 +1885,7 @@ async def async_process(
18791885
args.pop("extras")
18801886

18811887
if event and event.is_set():
1882-
raise StageCancelError(
1883-
"Execution was canceled from the event before start parallel."
1884-
)
1888+
raise StageCancelError("Cancel before start call process.")
18851889

18861890
args: DictData = self.validate_model_args(
18871891
call_func, args, run_id, parent_run_id, extras=self.extras
@@ -2101,19 +2105,41 @@ def process(
21012105
run_id=parent_run_id,
21022106
event=event,
21032107
)
2104-
# TODO: The context from workflow execution does not save when its status
2105-
# does not equal SUCCESS.
21062108
if result.status == FAILED:
21072109
err_msg: str = (
21082110
f" with:\n{msg}"
21092111
if (msg := result.context.get("errors", {}).get("message"))
21102112
else "."
21112113
)
2112-
raise StageNestedError(f"Trigger workflow was failed{err_msg}")
2114+
return result.catch(
2115+
status=FAILED,
2116+
context={
2117+
"status": FAILED,
2118+
"errors": StageError(
2119+
f"Trigger workflow was failed{err_msg}"
2120+
).to_dict(),
2121+
},
2122+
)
21132123
elif result.status == CANCEL:
2114-
raise StageNestedCancelError("Trigger workflow was cancel.")
2124+
return result.catch(
2125+
status=CANCEL,
2126+
context={
2127+
"status": CANCEL,
2128+
"errors": StageCancelError(
2129+
"Trigger workflow was cancel."
2130+
).to_dict(),
2131+
},
2132+
)
21152133
elif result.status == SKIP:
2116-
raise StageNestedSkipError("Trigger workflow was skipped.")
2134+
return result.catch(
2135+
status=SKIP,
2136+
context={
2137+
"status": SKIP,
2138+
"errors": StageSkipError(
2139+
"Trigger workflow was skipped."
2140+
).to_dict(),
2141+
},
2142+
)
21172143
return result
21182144

21192145

@@ -2939,10 +2965,13 @@ def process(
29392965
exceed_loop: bool = False
29402966
catch(context=context, status=WAIT, updated={"until": {}})
29412967
statuses: list[Status] = []
2968+
29422969
while until_rs and not (exceed_loop := (loop > self.max_loop)):
29432970

29442971
if event and event.is_set():
2945-
raise StageCancelError("Cancel before start loop process.")
2972+
raise StageCancelError(
2973+
f"Cancel before start loop process, (loop: {loop})."
2974+
)
29462975

29472976
status, context, item = self._process_nested(
29482977
item=item,
@@ -3043,6 +3072,30 @@ class CaseStage(BaseNestedStage):
30433072
... ],
30443073
... }
30453074
3075+
>>> stage = {
3076+
... "name": "If stage execution.",
3077+
... "case": "${{ param.test }}",
3078+
... "match": [
3079+
... {
3080+
... "case": "1",
3081+
... "stages": [
3082+
... {
3083+
... "name": "Stage case 1",
3084+
... "eche": "Hello case 1",
3085+
... },
3086+
... ],
3087+
... },
3088+
... {
3089+
... "else": [
3090+
... {
3091+
... "name": "Stage else",
3092+
... "eche": "Hello case else",
3093+
... },
3094+
... ],
3095+
... },
3096+
... ],
3097+
... }
3098+
30463099
"""
30473100

30483101
case: str = Field(description="A case condition for routing.")

tests/example/test_stage_foreach.py

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,46 +140,67 @@ def test_example_foreach_stage_exec_with_trigger_raise(test_path):
140140
"item": 1,
141141
"stages": {
142142
"2827845371": {
143-
"outputs": {},
143+
"outputs": {
144+
"params": {"item": 1},
145+
"jobs": {
146+
"first-job": {
147+
"status": FAILED,
148+
"stages": {
149+
"raise-stage": {
150+
"outputs": {},
151+
"errors": {
152+
"name": "StageError",
153+
"message": "Raise trigger with item: 1",
154+
},
155+
"status": FAILED,
156+
}
157+
},
158+
"errors": {
159+
"name": "JobError",
160+
"message": "Strategy execution was break because its nested-stage, 'raise-stage', failed.",
161+
},
162+
}
163+
},
164+
},
144165
"errors": {
145-
"name": "StageNestedError",
166+
"name": "StageError",
146167
"message": "Trigger workflow was failed with:\nJob execution, 'first-job', was failed.",
147168
},
148169
"status": FAILED,
149170
}
150171
},
151172
"errors": {
152173
"name": "StageError",
153-
"message": "Item execution was break because its nested-stage, 'Stage trigger for raise', failed.",
174+
"message": "Break item: 1 because nested stage: 'Stage trigger for raise', failed.",
154175
},
155176
},
156177
2: {
157178
"status": CANCEL,
158179
"item": 2,
159180
"stages": {
160181
"2827845371": {
161-
"outputs": {},
182+
"outputs": {"params": {"item": 2}, "jobs": {}},
162183
"errors": {
163-
"name": "StageNestedCancelError",
184+
"name": "StageCancelError",
164185
"message": "Trigger workflow was cancel.",
165186
},
166187
"status": CANCEL,
167188
}
168189
},
169190
"errors": {
170191
"name": "StageCancelError",
171-
"message": "Item execution was canceled from the event after end item execution.",
192+
"message": "Cancel item: 2 after end nested process.",
172193
},
173194
},
174195
},
175196
"errors": {
176-
1: {
177-
"name": "StageError",
178-
"message": "Item execution was break because its nested-stage, 'Stage trigger for raise', failed.",
179-
},
180197
2: {
181198
"name": "StageCancelError",
182-
"message": "Item execution was canceled from the event after end item execution.",
199+
"message": "Cancel item: 2 after end nested process.",
200+
},
201+
1: {
202+
"name": "StageError",
203+
"message": "Break item: 1 because nested stage: 'Stage trigger for raise', failed.",
183204
},
184205
},
185206
}
@@ -197,17 +218,38 @@ def test_example_foreach_stage_exec_with_trigger_raise(test_path):
197218
"item": 1,
198219
"stages": {
199220
"2827845371": {
200-
"outputs": {},
221+
"outputs": {
222+
"params": {"item": 1},
223+
"jobs": {
224+
"first-job": {
225+
"status": FAILED,
226+
"stages": {
227+
"raise-stage": {
228+
"outputs": {},
229+
"errors": {
230+
"name": "StageError",
231+
"message": "Raise trigger with item: 1",
232+
},
233+
"status": FAILED,
234+
}
235+
},
236+
"errors": {
237+
"name": "JobError",
238+
"message": "Strategy execution was break because its nested-stage, 'raise-stage', failed.",
239+
},
240+
}
241+
},
242+
},
201243
"errors": {
202-
"name": "StageNestedError",
244+
"name": "StageError",
203245
"message": "Trigger workflow was failed with:\nJob execution, 'first-job', was failed.",
204246
},
205247
"status": FAILED,
206248
}
207249
},
208250
"errors": {
209251
"name": "StageError",
210-
"message": "Item execution was break because its nested-stage, 'Stage trigger for raise', failed.",
252+
"message": "Break item: 1 because nested stage: 'Stage trigger for raise', failed.",
211253
},
212254
},
213255
2: {
@@ -216,18 +258,18 @@ def test_example_foreach_stage_exec_with_trigger_raise(test_path):
216258
"stages": {},
217259
"errors": {
218260
"name": "StageCancelError",
219-
"message": "Item execution was canceled from the event before start item execution.",
261+
"message": "Cancel item: 2 before start nested process.",
220262
},
221263
},
222264
},
223265
"errors": {
224266
2: {
225267
"name": "StageCancelError",
226-
"message": "Item execution was canceled from the event before start item execution.",
268+
"message": "Cancel item: 2 before start nested process.",
227269
},
228270
1: {
229271
"name": "StageError",
230-
"message": "Item execution was break because its nested-stage, 'Stage trigger for raise', failed.",
272+
"message": "Break item: 1 because nested stage: 'Stage trigger for raise', failed.",
231273
},
232274
},
233275
}

0 commit comments

Comments
 (0)