Skip to content

Commit

Permalink
working base plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinblack committed May 15, 2024
1 parent cece2ec commit 6783c80
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
26 changes: 11 additions & 15 deletions arcaflow_plugin_concat_lists/concat_lists_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,28 @@


@plugin.step(
id="hello-world",
name="Hello world!",
description="Says hello :)",
id="concat-lists",
name="Concatenate Lists",
description="Concatenates input lists into single output list",
outputs={"success": SuccessOutput, "error": ErrorOutput},
)
def hello_world(
def concat_lists(
params: InputParams,
) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]:
"""The function is the implementation for the step. It needs the decorator
above to make it into a step. The type hints for the params are required.

output_list = []

for list in params.input_lists:
output_list += list

:param params:
:return: the string identifying which output it is, as well the output
structure
"""

return "success", SuccessOutput("Hello, {}!".format(params.name))
return "success", SuccessOutput(output_list)


if __name__ == "__main__":
sys.exit(
plugin.run(
plugin.build_schema(
# List your step functions here:
hello_world,
concat_lists,
)
)
)
24 changes: 11 additions & 13 deletions arcaflow_plugin_concat_lists/concat_lists_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@

import typing
from dataclasses import dataclass
from arcaflow_plugin_sdk import validation
from arcaflow_plugin_sdk import schema


@dataclass
class InputParams:
"""
This is the data structure for the input parameters of the step defined
below.
"""

name: typing.Annotated[str, validation.min(1)]
input_lists: typing.Annotated[
typing.List[typing.List[typing.Any]],
schema.name("input lists"),
schema.description("List of lists to concatenate")
]


@dataclass
class SuccessOutput:
"""
This is the output data structure for the success case.
"""

message: str
output_list: typing.Annotated[
typing.List[typing.Any],
schema.name("output list"),
schema.description("Concatenated list")
]


@dataclass
class ErrorOutput:
"""
This is the output data structure in the error case.
"""

error: str
35 changes: 21 additions & 14 deletions tests/test_arcaflow_plugin_concat_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,39 @@
from arcaflow_plugin_sdk import plugin


class HelloWorldTest(unittest.TestCase):
class ConcatListsTest(unittest.TestCase):
@staticmethod
def test_serialization():
plugin.test_object_serialization(concat_lists_plugin.InputParams("John Doe"))
plugin.test_object_serialization(concat_lists_plugin.InputParams(
[
["a", "b", "c"],
[1, 2, 3],
]
))

plugin.test_object_serialization(
concat_lists_plugin.SuccessOutput("Hello, world!")
concat_lists_plugin.SuccessOutput(
["a", "b", "c", 1, 2, 3]
)
)

plugin.test_object_serialization(
concat_lists_plugin.ErrorOutput(error="This is an error")
)

def test_functional(self):
input = concat_lists_plugin.InputParams(name="Example Joe")
# def test_functional(self):
# input = concat_lists_plugin.InputParams(name="Example Joe")

output_id, output_data = concat_lists_plugin.hello_world(
params=input, run_id="plugin_ci"
)
# output_id, output_data = concat_lists_plugin.hello_world(
# params=input, run_id="plugin_ci"
# )

# The example plugin always returns an error:
self.assertEqual("success", output_id)
self.assertEqual(
output_data,
concat_lists_plugin.SuccessOutput("Hello, Example Joe!"),
)
# # The example plugin always returns an error:
# self.assertEqual("success", output_id)
# self.assertEqual(
# output_data,
# concat_lists_plugin.SuccessOutput("Hello, Example Joe!"),
# )


if __name__ == "__main__":
Expand Down

0 comments on commit 6783c80

Please sign in to comment.