Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect invalid step return #134

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/arcaflow_plugin_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5989,10 +5989,17 @@ def __call__(
input.validate(params, tuple(["input"]))
# Run the step
result = self._handler(step_local_data.initialized_object, params)
if not isinstance(result, tuple):
raise BadArgumentException(
f"The implementation of step {run_id}/{self.id} returned"
f" type {type(result)}; expected a tuple with two"
dbutenhof marked this conversation as resolved.
Show resolved Hide resolved
" values: output ID string and a step-specific value."
)
if len(result) != 2:
raise BadArgumentException(
"The step returned {} results instead of 2. Did your step"
" return the correct results?".format(len(result))
f"The implementation of step {run_id}/{self.id} returned"
f"{len(result)} results instead of 2. Did your step"
dbutenhof marked this conversation as resolved.
Show resolved Hide resolved
" return the correct results?"
webbnh marked this conversation as resolved.
Show resolved Hide resolved
)
output_id, output_data = result
if output_id not in self.outputs:
Expand Down
34 changes: 27 additions & 7 deletions src/arcaflow_plugin_sdk/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
import typing
import unittest

from arcaflow_plugin_sdk import plugin
from arcaflow_plugin_sdk import plugin, schema


@dataclasses.dataclass
class StdoutTestInput:
class EmptyTestInput:
pass


@dataclasses.dataclass
class StdoutTestOutput:
class EmptyTestOutput:
pass


@plugin.step(
"stdout-test",
"Stdout test",
"A test for writing to stdout.",
{"success": StdoutTestOutput},
{"success": EmptyTestOutput},
)
def stdout_test_step(
input: StdoutTestInput,
) -> typing.Tuple[str, StdoutTestOutput]:
_: EmptyTestInput,
) -> typing.Tuple[str, EmptyTestOutput]:
webbnh marked this conversation as resolved.
Show resolved Hide resolved
print("Hello world!")
return "success", StdoutTestOutput()
return "success", EmptyTestOutput()


class StdoutTest(unittest.TestCase):
Expand All @@ -52,5 +52,25 @@ def cleanup():
self.assertEqual("Hello world!\n", e.getvalue())


@plugin.step(
"incorrect-return",
"Incorrect Return",
"A step that returns a bad output which omits the output ID.",
{"success": EmptyTestOutput},
)
def incorrect_return_step(
_: EmptyTestInput,
): # Skip return type, since we're purposefully not doing it right.
return EmptyTestOutput()
webbnh marked this conversation as resolved.
Show resolved Hide resolved


class CallStepTest(unittest.TestCase):
def test_incorrect_return_args_count(self):
s = plugin.build_schema(incorrect_return_step)

with self.assertRaises(schema.BadArgumentException):
s.call_step(self.id(), "incorrect-return", EmptyTestInput())
webbnh marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
unittest.main()