Skip to content

Commit 16bdd47

Browse files
❤️️ TEST: Updated
1 parent fac26f3 commit 16bdd47

File tree

2 files changed

+123
-3
lines changed

2 files changed

+123
-3
lines changed

tests/test_flow.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python
2+
3+
from dotflow import DotFlow, action
4+
5+
6+
@action(retry=5)
7+
class StepX:
8+
9+
@action
10+
def first_function(self):
11+
return {"foo": "bar"}
12+
13+
@action
14+
def second_function(self):
15+
return True
16+
17+
18+
@action(retry=5)
19+
class StepY:
20+
21+
def __init__(self, initial_context):
22+
print(initial_context.storage, "__init__")
23+
assert initial_context.storage
24+
self.variable = True
25+
26+
def auxiliary_function(self):
27+
"""This function will not be executed, because
28+
it does not have an 'action' decorator.
29+
"""
30+
31+
@action
32+
def first_function(self, initial_context):
33+
print(initial_context.storage, "first_function")
34+
assert initial_context.storage
35+
assert self.variable
36+
37+
return {"foo": "bar"}
38+
39+
@action
40+
def second_function(self, previous_context):
41+
print(previous_context.storage, "second_function")
42+
assert previous_context.storage
43+
44+
return True
45+
46+
47+
@action
48+
def simple_step():
49+
return "ok"
50+
51+
52+
@action
53+
def extract_task_x():
54+
return "extract"
55+
56+
57+
@action
58+
def transform_task_x(initial_context, previous_context):
59+
print(initial_context.storage, "initial_context")
60+
print(previous_context.storage, "previous_context")
61+
62+
assert initial_context.storage, {"foo": True}
63+
assert previous_context.storage, "extract"
64+
65+
return "transform"
66+
67+
68+
@action
69+
def load_task_x():
70+
return "load"
71+
72+
73+
@action
74+
def extract_task_y():
75+
print("extract")
76+
return "extract"
77+
78+
79+
@action
80+
def transform_task_y(previous_context):
81+
print(previous_context.storage, "transform")
82+
assert previous_context.storage, "extract"
83+
84+
return "transform"
85+
86+
87+
@action
88+
def load_task_y(previous_context):
89+
print(previous_context.storage, "load")
90+
assert previous_context.storage, "transform"
91+
92+
return "load"
93+
94+
95+
def main():
96+
workflow = DotFlow()
97+
98+
workflow.task.add(step=StepX)
99+
workflow.task.add(step=StepY, initial_context={"foo": "bar"})
100+
workflow.task.add(step=simple_step)
101+
workflow.task.add(step=simple_step)
102+
workflow.task.add(step=simple_step)
103+
workflow.task.add(step=simple_step)
104+
workflow.task.add(step=simple_step)
105+
workflow.task.add(step=simple_step)
106+
workflow.task.add(step=simple_step)
107+
workflow.task.add(step=simple_step)
108+
workflow.task.add(step=extract_task_x)
109+
workflow.task.add(step=transform_task_x, initial_context={"foo": True})
110+
workflow.task.add(step=load_task_x)
111+
workflow.task.add(step=extract_task_y)
112+
workflow.task.add(step=transform_task_y)
113+
workflow.task.add(step=load_task_y)
114+
workflow.start()
115+
116+
return workflow
117+
118+
119+
if __name__ == "__main__":
120+
main()

tests/test_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from examples.cli_with_mode import main as cli_with_mode
88
from examples.cli_with_output_context import main as cli_with_output_context
99
from examples.cli_with_path import main as cli_with_path
10-
from examples.cli import main as cli
10+
from examples.simple_cli import main as simple_cli
1111
from examples.simple_class_workflow import main as simple_class_workflow
1212
from examples.simple_function_workflow_with_error import main as simple_function_workflow_with_error
1313
from examples.simple_function_workflow import main as simple_function_workflow
@@ -44,8 +44,8 @@ def test_cli_with_output_context(self):
4444
def test_cli_with_path(self):
4545
cli_with_path()
4646

47-
def test_cli(self):
48-
cli()
47+
def test_simple_cli(self):
48+
simple_cli()
4949

5050
def test_simple_class_workflow(self):
5151
simple_class_workflow()

0 commit comments

Comments
 (0)