Add ability to resolve workflows within applications, closes #290

This commit is contained in:
davidmezzetti
2022-06-03 09:27:08 -04:00
parent 4aafae4a79
commit 917b2cfe59
2 changed files with 29 additions and 0 deletions
+5
View File
@@ -242,9 +242,14 @@ class Application:
resolved function
"""
# Check if function is a pipeline
if function in self.pipelines:
return self.pipelines[function]
# Check if function is a workflow
if function in self.workflows:
return self.workflows[function]
# Attempt to resolve action as a callable function
return PipelineFactory.create({}, function)
+24
View File
@@ -477,6 +477,30 @@ class TestWorkflow(unittest.TestCase):
"And another sentence to split.",
)
def testYamlWorkflowTask(self):
"""
Tests YAML workflow with a workflow task
"""
# Create function and add to module
def action(elements):
return [x * 2 for x in elements]
sys.modules[__name__].action = action
workflow = """
workflow:
run:
tasks:
- testworkflow.action
flow:
tasks:
- run
"""
app = API(workflow)
self.assertEqual(list(app.workflow("flow", [1, 2])), [2, 4])
def testYamlTransformWorkflow(self):
"""
Test reading a YAML transform workflow in Python.